depending on the scope of the variable, it can be divided intoLocal Variables:
Definition: A variable defined inside a function or code block
Scope: Start with the line that defines the variable until the end of the code block
Declaration period: Allocates storage space from the line that defines the face, which is recycled after the code block is finished
No fixed initial value
Global Variables:
Definition: A variable defined outside a function
Scope: Starts from the line that defines the variable, until the end of the file (all functions can be shared)
Declaration period: Allocates storage space from the row that defines the variable and is destroyed when the program exits
The default disposition is 0.
Code Exercise:
#include <stdio.h> int age; Define global Variables Agevoid test () {Age = 10;} int main () { printf ("Age =%d\n", age); Output age = 0 test (); printf ("Age =%d\n", age); Output Age = 10
The first output is 0, because there is no age variable within the main function and age outside the main function is a global variable, and it is not initialized, so the default value of 0 is maintained.
The second output is ten; the test function finishes executing the age variable and is destroyed, and the global variable is accessed here
"Dark Horse programmer" Local variables and global variables (C language)