October 2004
Beginner
408 pages
9h 24m
English
The final topic we'll discuss in this chapter is variable scope—in other words, where variables exist. This is pertinent to functions because variables within a function are not accessible by code outside a function. And, for that matter, variables outside a function are not necessarily accessible inside the function.
Understanding Static VariablesVariables within functions are different not only because of variable scope but also because they can be static. Let's start with this example:
void up_one (void) {
int num = 0;
printf ("%d\n", ++num);
}
Even though num is incremented with each up_one() call, its ending value will only be 1 because it's reinitialized to 0 each time the function is called. In other words, ... |