(1) the pointer is the address.
First, let's clarify the point that the pointer is the address. This is the first step in understanding pointers.
Intuitively, the variable address
Int main () {int Foo; int * foo_p; Foo = 5; foo_p = & Foo; printf ("foo... % d \ n ", foo); printf (" * foo_p... % d \ n ", * foo_p); printf (" & FOO... % P \ n ", & Foo); printf (" foo_p... % P \ n ", foo_p); printf (" & foo_p... % P \ n ", & foo_p); Return 0 ;}
Run
Notes:
- P in % P refers to pointer (pointer), which is used to print the content in the pointer variable.
- Sometimes % x is used to print the pointer. Although the result is the same, the meaning is completely different. % P: output the address of another variable stored in the pointer variable in an appropriate way (usually in hexadecimal format); % x: print the value of the variable in hexadecimal format. In addition, if % x is used to print pointer variables in my environment, the preceding 0 is omitted.
Pointer variable
The variable name is in the upper left corner, the variable address is in the upper right corner, and the variable storage content is in the middle.
Check the memory size allocated for each basic type in my environment
Int main () {printf ("sizeof (char )... % d \ n ", sizeof (char); printf (" sizeof (INT )... % d \ n ", sizeof (INT); printf (" sizeof (float )... % d \ n ", sizeof (float); printf (" sizeof (double )... % d \ n ", sizeof (double); printf (" sizeof (int *)... % d \ n ", sizeof (int *); Return 0 ;}
In my environment, the size of pointer type allocation is sizeof (int *) = 4; that is to say, 4 bytes are used to store the variable address, this is also the result of most environments. Based on this result, we will discuss it later. As for the C standard, the size of the pointer type is not specified, and the specific size depends on the specific environment.
C pointer (1) pointer is the address