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 searching from the nearest scope until you find the variable
#include <stdio.h>int main (int argc, const char * argv[]) { int a = +; { int a = $; 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. C Language Variable memory Analysis C language addressing from large to small
1 #include <stdio.h> 2 3 int main (int argc, const char * argv[]) {4 int a =; 5 int b = n; 6 7 printf ("The address of A is%d\n", &a); 8 printf ("The address of B is%d\n", &b); 9 return 0;1 1}
Out
The address of A is 1606416268
The address of B is 1606416264
-"4 bytes apart, from big to small
[C language-2] C Language Variables