[C language, C Language
A. variable scope: 1. local variables: the scope of variables defined within a function or code block: from the definition point to the end of the code block lifecycle: allocate controls from the definition point. After the code block ends, the collected local variables do not have default values, initialize it by yourself. global variables: Scope of variables defined outside the function: from the definition point to the end of the file (can be shared by all subsequent functions) lifecycle: Allocate space for program startup, the program exits and recycles global variables. The default value is 0.
From the latest scope to 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
It is suitable for block usage, which can improve performance. After the execution of the variables defined in the memory block is recycled in a timely manner, B. Memory Analysis of C language variables C language addressing from large to small
1 # include <stdio. h> 2 3 int main (int argc, const char * argv []) {4 int a = 100; 5 int B = 200; 6 7 printf ("The address of a is % d \ n", & a); 8 printf ("The address of B is % d \ n", & B ); 9 10 return 0; 11}
Out:
The address of a is 1606416268
The address of B is 1606416264
-4 bytes different from large to small