Prepare content: The address of the variable, the contents of the variable, direct addressing, and indirection.
(1). The address of the variable
The first address of the storage space that the variable occupies in memory.
(2). The contents of the variable
(3). Direct addressing
Access to the contents of a variable directly by variable name.
(4). Indirect addressing
Indirectly access the variable (such as a) to which it points through a pointer variable, such as P.
1. What is a pointer?
In order to access these memory cells correctly, each memory unit must be numbered. The number of the memory unit is also called the address. Since the memory unit can be found according to the number or address of the memory unit, it is often referred to as a pointer.
2. What is a pointer variable?
In the C language, a variable is allowed to hold a pointer, which is called a pointer variable. In the C language, a data type or structure often occupies a contiguous set of memory units. The concept of "address" does not describe a data type or structure well, while a "pointer" is actually an address, but it is the first address of a data structure, which is "pointing" to a data structure, thus making the concept clearer.
The pointer to the variable is the address of the variable. The variable that holds the variable address is a pointer variable.
3. Definition of pointer variables
The general form is:
Type descriptor * variable name;
where * indicates that this is a pointer variable, the variable name is the defined pointer variable name, and the type specifier represents the data type of the variable to which this pointer variable is pointing.
4. Reference to pointer variables:
Pointer variables, like ordinary variables, need to be defined not only by the description, but also by a specific value. An unassigned pointer variable cannot be used, otherwise it will cause system confusion and even panic. The assignment of a pointer variable can only be assigned to an address and must never be given any other data, or it will cause an error. In the C language, the address of a variable is assigned by the compilation system, completely transparent to the user, and the user does not know the specific address of the variable.
Two related operators:
- &: Take address operator;
- *: pointer operator (or "indirect access" operator).
The address operator & is provided in the C language to represent the address of the variable. The general form is:
& variable name;
If &a represents the address of variable A, &b represents the address of variable B.
5. Application of pointer variables
C Language Pointers