3. Function scope
Each function in the Turbo C2.0 is a separate block of code that is owned by the function code, and is not accessible to any statement in any other function except for a call to a function. For example, if you use a jump statement goto, you cannot jump from one function to another. Unless you use the whole variable, the program code and data defined inside a function do not interact with the program code and data in another function.
The scope of all functions in Turbo C2.0 is at the same nesting level, that is, you cannot describe or define another function within one function.
In Turbo C2.0, a function is invoked on the other child functions, that is, the function is in a different file, without having to append any descriptive statements to another function, which means that a function is visible to the entire program.
4. Variable scope of function
In Turbo C2.0, variables can be described at various levels of subroutines, that is, in any function, the variable indicates that it is allowed to be described only at the beginning of a function body, and that the description of the variable (including initialization) is followed by the left curly brace of a compound statement until the paired right curly brace. Its scope is only within this pair of curly braces, and it will no longer exist when the program executes to the curly braces. Of course, the variables in the inner layer are not related to each other even if they are the same as the variable names in the outer layers.
Example 9.
#include <stdio.h>
int i=10;
int main ()
{
int i=1;
printf ("%d\t, I");
{
int i=2;
PRITNF ("%d\t", I);
{
extern i;
I+=1;
printf ("%d\t", I);
}
printf ("%d\t", ++i);
}
printf ("%d\n", ++i);
return 0;
}
Run result is
1 2 11 3 2
The results from the program running are not difficult to see the relationship between the variables in the program, as well as the scope of each variable.