Today began to learn pointers, pointers in C language has a very important position, according to the teacher said, learning C is not good pointers and not learning, the visible pointer in the C language of the important position. Don't say much, first we need to know what is a pointer.
Pointer: A pointer is a variable that stores the memory address of another object, and if one variable stores the address of another object, the variable is said to point to the object.
In other words pointers are also variables, except that, unlike normal variables, stored in memory by another object is stored within the pointer. The value inside the pointer is a hexadecimal value.
Because pointer values are data, pointer variables can be assigned values, so a pointer to the point can be changed in the execution of the program. The pointer p points to the variable x at some point in execution, and to the variable y at another point
1. The format of the definition
L Data Type * pointer variable name ;
L int *p;
2. Define the Post assignment first
L Simple Value
int a = 10;
int *p;
p = &a; [A1]
printf ("%d", *p[a2]);
int nums[10];
P=nums;
L Simple Change value
*p = 9;
3. Assigning values at the same time as defined
int a = 10;
int *p = &a;
4. Attention Points
l int *p; p = 1000;
l int *p; *p = 100;
l int *p; *p = &a;
L &P The address value stored in the output pointer
L Other pointer type description, such as float *p; Char *p;
The type cannot be used indiscriminately, such as int a = 10; float *p = &a;
[A1] Assigns a value to the pointer, the right side of the assignment operator must be an address, if it is a normal variable needs to be preceded by an address operator &; if it is another pointer variable or an array, do not need to add the & operator
- The [A2] operator * is used to return the value stored in the memory address pointed to by the pointer
C Language Learning Seventh chapter