A. Variable scope: 1. Local variables: variable scopes defined inside a function or code block: from definition to the end of code block lifecycle: Assign a control from a definition, and then recycle a local variable without a default value after the code block ends, and initialize 2 yourself. Global variables: variable scope defined outside the function: from the definition to the end of the file (can be shared by all subsequent functions) life cycle: The program starts allocating space, the program exits the recycle global variable has a default value of 0 start from the nearest scope until you find the variable # include <stdio.h>
int main (int argc, const char * argv[]) {
int a = 100;
{
int a = 200;
printf ("A =%d\n", a);
}
printf ("A =%d\n", a);
return 0;
} out:
A = 200
A = 100
Suitable use of blocks, can improve performance, in a timely manner to reclaim the variables defined in the memory block after execution will be recycled B. Memory analysis of C language Variables C language addressing from large to small # include <stdio.h>
int main (int argc, const char * argv[]) {
int a = 100;
int b = 200;
printf ("The address of A is%d\n", &a);
printf ("The address of B is%d\n", &b);
return 0;
} out:
The address of A is 1606416268
The address of B is 1606416264
-"4 bytes apart, from big to small
2. C Language Variables