This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
The position of pointer in C language is needless to say.
The pointer concept pointer is a special variable, and the values stored in it are interpreted as an address in memory. A pointer has four elements: pointer type, pointer type, pointer value, or memory zone pointed to by the pointer, and the memory zone occupied by the pointer. Therefore, to understand pointers, you must understand these four elements. For example. Let's take a look at an example to illustrate what the four elements of pointers represent: Example 1.
(1) int * PTR;
(2) char * PTR;
(3) int ** PTR;
(4) int (* PTR) [3];
(5) int * (* PTR) [4];
Four elements of pointer
1. pointer type
From the perspective of syntax, to get the pointer type, you only need to remove the pointer name in the pointer declaration statement, and the rest is the pointer type, this is the type of the pointer, and it is different from the type pointed to by the pointer. The following explains the types of pointers in the above example:
(1) int * PTR; // the pointer type is int *
(2) char * PTR; // the pointer type is char *
(3) int ** PTR; // the pointer type is int **
(4) int (* PTR) [3]; // the pointer type is int (*) [3]
(5) int * (* PTR) [4]; // the pointer type is int * (*) [4]
2. When the pointer points to a type that accesses the memory area pointed to by the pointer, the type pointed to by the pointer determines what the compiler treats the content in the area.
From the perspective of syntax, to get the type pointed to by the pointer, you only need to remove the pointer name and the pointer declarative * on the left of the name in the pointer declaration statement, the rest is the type pointed to by the pointer. After this explanation, let's look at the type pointed to by each pointer in the above example:
(1) int * PTR; // The Pointer Points to an int type.
(2) char * PTR; // The Pointer Points to a char type.
(3) int ** PTR; // The type pointed to by the pointer is int *
(4) int (* PTR) [3]; // The type pointed to by the pointer is int () [3]
(5) int * (* PTR) [4]; // The type pointed to by the pointer is int * () [4]
Note:
The pointer type (the pointer type) is different from the pointer type.
3. the pointer value refers to the memory address or memory area pointed to by the pointer.
The pointer value refers to the value stored by the pointer itself. This value will be treated as an address by the compiler, rather than a general value. In a 32-bit program, the value of all types of pointers is a 32-bit integer .. For a 64-bit system, the pointer value is a 64-bit integer.
The memory area pointed to by the pointer starts from the memory address represented by the pointer value, and the length is a memory area of sizeof (type pointed to by the pointer. Generally, when we say that the value of a pointer is X, it means that the Pointer Points to the memory area with X as the first address, which means that the value of this pointer is the first address of this memory area.
Note:
The memory zone pointed to by the pointer and the type pointed to by the pointer are two completely different concepts. Taking the above example as an example, the Type pointed to by the pointer already exists, but since the pointer is not initialized, the memory zone it points to does not exist.
4. the memory occupied by the pointer itself refers to the amount of memory occupied by the pointer itself. You can use sizeof (pointer type) to understand it. In a 32-bit system, the pointer occupies the length of 4 bytes.
The above is about the pointer concept and four elements of the pointer, which is crucial for understanding the pointer and for pointer operations.
C pointer parsing ------ concepts and elements of pointers