September 1998
Intermediate to advanced
848 pages
20h 13m
English
We gave storage classes a passing mention in Chapter 10, "Arrays and Pointers," but let's take a more in-depth look now. As mentioned in Chapter 10, local variables are known only to the functions containing them. However, C also offers the possibility of global variables, those known to several functions. Suppose you want both main() and critic() to have access to the variable Units. You can do this by declaring Units so that it belongs to the external storage class, as shown in Listing 13.1. (Here we follow a common, but not universal, convention of uppercasing the first character of a global variable name.)
/* global.c -- uses an external variable */ #include <stdio.h> int Units; ... |
Read now
Unlock full access