I understand it:
int i = 3; // declaration with definition
It tells the compiler:
3
But what does this declaration say to the compiler:
int i; // declaration
The announcement tells the compiler to reserve a place for the variable iand map the name ito this space (your points 1 and 2).
i
If iis a global variable, it is initialized 0.
0
, i undefined (, , - ), .
: (.. ) .
int i; : i, int, , int. , , . , i, , . , .. , . , .
int i;
int
, int i i. : . . , . i , , 0. :
int i
int i; /* ... more code ...*/ int i;
i 0 (, i ). :
int i; int i = 3;
, i 3 .
, 0. 0 , , , ( ) .
, , i. undefined.
, :
i int, ( i ). , , "":
, undefined. , . . , : undefined.
, int i; , , : "i - int, . , ". , C .
:
1) ( "", ). ; 2) ( ); 3) (, malloced).
"int i;" , . , ( "" .
Objects created in external memory are initialized to zero if they are not explicitly initialized (for example, "int i = 3";
You can create an external object in a function using the "static" keyword.
int a; // external memory with "global" scope. Initialized to 0 implicitly. static int b; // external memory with file (module) scope. Initialized to 0 implicitly. int c = 3; // external memory initialized to 3. f() { int d; // created on the stack. Goes away when the block exits. Filled with random trash because there is no initialization. int e = 4; // stack object initialized to 3. static int f; // "f" is external but not global. Like all externals, it implicitly initialized to zero. static int g = 3; // An external like f but initialized to 3. }