Local variables:
Created on the stack (growing down), the life cycle exists in the current scope.
is a random value if it is not initialized at the time of creation.
Global variables:
Created in the static zone, the life cycle is always present.
0 if it is not initialized at the time of creation.
Static local variables:
The external link properties are severed. Created in the static zone.
0 if it is not initialized at the time of creation.
The storage of global variables and static variables is placed in a block, initialized global variables and static variables in an area, uninitialized global variables and uninitialized static variables in another adjacent area.
Global static variables:
The external link attribute is cut off and created in the static zone, and the life cycle persists.
0 if it is not initialized at the time of creation.
#include <stdio.h> #include <stdlib.h>int fun1 () {static int n = 0; n++; return n;} int main () {int ret = 0; for (int i = 0; i < ten; i++) {ret = FUN1 (); printf ("%d\n", ret); } system ("Pause"); return 0;}
Output-------... 10.
#include <stdio.h> #include <stdlib.h>static int n;int fun1 () {n = 0; n++; return n;} int main () {int ret = 0; for (int i = 0; i < ten; i++) {ret = FUN1 (); printf ("%d\n", ret); } system ("Pause"); return 0;}
Output 10 x 1.
extern
External file can be detected with external link properties.
Static
Cut off external link properties.
Variables located in the static zone:
The entire life cycle exists, such as global variables, static variables.
#include <stdio.h> #include <stdlib.h>int b = 20;int Main () {static int a = 10; int c = 5; printf ("%p\n", &a); printf ("%p\n", &b); printf ("%p\n", &c); System ("pause"); return 0;}
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7A/D8/wKiom1a-jrqBc9_PAABPx4qeNu0367.png "title="%4m) FK {5~ijfhpdbiafjeg2.png "alt=" Wkiom1a-jrqbc9_paabpx4qenu0367.png "/>
It can be concluded that the storage address of the static variable and the global variable is very close, in the same region, namely: are stored in the static zone.
This article is from the "C language 100-200 Prime" blog, please be sure to keep this source http://10740184.blog.51cto.com/10730184/1741752
C language Local variables, global variables, local static variables, global static variables, extern,static differences