[Learning notes] [C Language] variable type, learning notes variable
According to the scope of the variable, it can be divided:
1. Local variables:
1> definition: variables defined within a function (code block) (including the form parameters of the function)
2> scope: Starting from the line that defines the variable until the end of the code block
3> lifecycle: the bucket is allocated from the row where the variable is defined. After the code block ends, it is recycled.
4> no Fixed Initial Value
2. Global Variables
1> definition: variables defined outside the Function
2> scope: starts from the line that defines the variable and ends with the end of the file (can be shared by all functions below)
3> life cycle: Once a program is started, it will allocate storage space, and the program will be destroyed only when it exits.
4> the default initial value is 0.
1 // global variables: a, B, c 2 // local variables: v1, v2, e, f 3 4 # include <stdio. h> 5 // The initial value of variable a is 10 6 int a = 10; 7 8 // The initial value of variable B is 0 9 // The initial value of variable c is 2010 int B, c = 20; 11 12 int sum (int v1, int v2) 13 {14 return v1 + v2; 15} 16 17 void test () 18 {19 B ++; 20 21 int I = 0; 22 I ++; 23 24 printf ("B = % d, I = % d \ n", B, I ); 25} 26 27 int main () 28 {29 test (); 30 test (); 31 test (); 32 33 int e = 10; 34 35 {36 {37 int f = 30; 38} 39} 40 41 return 0; 42}