1. Each variable in the C language has 3 properties: storage age, scope, link
1) Shelf life: The duration of the variable's storage determines how long the memory reserved for the variable is freed. A total of 2, automatic storage period (auto), static storage period (static), automatic storage (auto) variable when the owning block is executed to obtain the memory unit, and the block terminates when the memory unit is freed, automatically obtain or free memory, hence the name auto. A static stored variable (static) always occupies the same memory unit while the program is running, static and static.
2) Scope: The scope of the variable refers to the part of the program text that can use the variable. A total of 2, block scopes are visible from the declaration location to the end of the block, where the file scope is visible from the point of declaration to the end of the file.
3) Link: A variable's link refers to different parts of the program that can share this variable. A total of 3, external links refers to the program can be different file sharing, internal link refers to only a single file, no link refers to a single function, and can not be shared at all.
2. The default storage age, scope, and link of a variable depend on the declaration position of the variable.
1) variables declared within blocks: Automatic storage term, block scope, no link.
2) variables declared at the outermost part of the program (outside any block): Static storage age, file scope, external link.
int i; // static storage, file scopes, external links void f (void) { INT J; // Auto-store, block scope, no link }
3, the special use of static:
1) When outside the block, the static description variable is an internal link, note: A variable declared outside the block has an external link, plus static, becomes an internal link, the external is not visible.
2) when inside a block, static indicates that the variable is stored for static duration, note that the variable is automatically stored within the block.
Static int i; // static storage age, file scope, internal link void f (void) { staticint J; // static storage, block scope, no link }
C-language storage type and keywords extern, static