Depending on the scope of the variable, it can be divided into:
1. Local Variables:
1> definition: Variables defined inside a function (block of code) (including formal parameters of a function)
2> scope: Start with the line that defines the variable until the end of the code block
3> life cycle: Allocates storage space from the row that defines the variable, which is recycled when the code block ends
4> does not have a fixed initial value
2. Global variables
1> definition: Variables defined outside the function
2> scope: Starts from the line that defines the variable and continues to the end of the file (can be shared by all subsequent functions)
3> life cycle: When a program starts, it allocates storage space and is destroyed when the program exits.
4> The default initial value is 0
1 //Global variables: A, B, C2 //Local Variables: v1, v2, E, F3 4#include <stdio.h>5 //the initial value of variable A is ten6 intA =Ten;7 8 //the initial value of variable B is 0.9 //the initial value of the variable C isTen intB, C = -; One A intSumintV1,intv2) - { - returnV1 +v2; the } - - voidTest () - { +b++; - + inti =0; Ai++; at -printf"b=%d, i=%d\n", B, i); - } - - intMain () - { in test (); - test (); to test (); + - intE =Ten; the * { $ {Panax Notoginseng intf = -; - } the } + A return 0; the}
"Learning note", "C language" variable type