Basic concepts of pointers in C language and basic concepts of pointers in C Language
Basic concepts of pointers in C Language
# Include "stdafx. h "int main () {int a = 3, * p; p = & a; // assign the address of variable a to pointer p, that is, p points to aprintf ("a = % d, * p = % d \ n", a, * p ); // output the value of variable a and the value of variable a pointed to by pointer p (* p indicates the value of p pointing to the variable) * p = 10; // equivalent to re-assigning printf ("a1 = % d, * p1 = % d \ n", a, * p); printf ("please input new: "); scanf (" % d ", & a); // input a. The input value is actually stored in the memory unit where the variable is located, that is, the address printf ("a2 = % d, * p2 = % d \ n", a, * p); (* p) ++; printf ("a3 = % d, * p3 = % d \ n ", a, * p); return 0 ;}
Note:
1. the pointer Declaration * is used to define the pointer variable, indicating that the defined variable is a pointer.
2. When defining multiple pointer variables, you must add *
3. Assign the variable address to the pointer: p = &
4. p is the address, * p is the variable pointed to by the address, that is,.
5. If p = & a, * p = * &
6. (* p) ++ is equivalent to a ++, * p = * p + 1 is equivalent to a = a + 1, ++ * p is equivalent to ++.
7. * p ++ is equivalent to * (p ++). That is, the value of * p (the value of a) is used as the value of the expression, add 1 to the address bit of p. After the operation, p no longer points to.
8. A value cannot be used as the initial value of the pointer variable, but a pointer variable can be initialized as a null pointer,
Example: int * p = 1000 Error
Int * p = 0 is correct. This 0 is the NULL value of the ASCII character, that is, the pointer variable is initialized as a NULL pointer.
& P pointer p address