// ============================= C pointer programming path ==================== ================== //
/// // The first note ////////////////
* Indicates that the variable is a pointer variable, which is also a feature of the pointer variable.
Int * pstu; // defines the pointer variable pstu, And the pstu points to the int type variable.
Static int * pstu; // defines the pointer variable pstu, And the pstu points to the static integer variable.
Char * pstu; // pstu is a pointer variable.
Accessors and value operators *
Get the address of a variable through &
You can use * to obtain the data stored in a variable.
Char stuname, name; // defines the stuname, name
Char * pstu // defines the pointer variable pstu pointing to the character type variable
Char * pnew // defines the pointer variable pnew to the variable type.
Pstu = & stuname // get the address of the stuname variable and assign it to the pointer variable pstu
Pnew = pstu // assign the pointer variable pstu value to pnew
Name = * pnew // assign the value of the memory unit pointed to by pnew to name
Int num_temp; // defines the variable num_temp.
Int * p_num; // defines the pointer variable.
P_num = & num_temp; // point p_num to num_temp
* P_num = 5; // assign a value to the variable pointed to by p_num
Sample Code:
# Include <stdio. h>
Int main ()
{
Int num;
Int * p_num;
P_num = & num;
* P_num = 5;
Printf ("% d \ n", num );
Return 0;
}
The output value is 5;
It indicates that the value is assigned to the num pointed to by p_num;
A normal variable must be defined in use first, and a pointer variable must be defined first, and a value must be assigned before use.
Assign values to the corresponding values (initialization ).
Example:
Int X, * P;
Float y;
P = & X; // correct
P = & Y; // Error
Subtraction of integers in the pointer field:
Here the address is changed.
Example:
# Include <stdio. h>
Int main ()
{
Int num [4] = {12, 13, 14, 15 };
Int * p_new, * p_old;
P_new = num;
Printf ("% d \ n", p_new );
P_new ++;
Printf ("% d \ n", p_new );
P_new = p_new + 2;
Printf ("% d \ n", p_new );
Return 0;
}
Addition and subtraction of pointers and pointers:
Of course, the premise is that there are two pointers, the main operation in the array, the difference between the two elements is the distance, or can be said to evaluate the number of elements between the two pointers.
C pointer programming path-first note