C pointer parsing ------ operators & amp; and *
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
& Is an address operator. * is a pointer or indirect operator. & The operation result of a is a pointer. the pointer type is a type plus *. The pointer type is a type, the pointer value, that is, the memory zone pointed to by the pointer, is the address of. * P has more computation results. In short, * p is what p points to. It has these characteristics: its type is the type pointed to by p, the address it occupies is the address pointed to by p.
See the following example:
Int a = 5;
Int B;
Int * p;
Int ** q;
P = & a; // The result of & a is a pointer of the int type *, int type, and a type.
* P = 10; // * p result. Here its type is int, and the address it occupies is the address pointed to by p, that is, the address of. Obviously, * p is variable a. The essence of this Code is to assign a value to.
Q = & p; // The result of & p is a pointer. The type is p type plus *. Here it is int **. The Pointer Points to the p type. Here it is int *. The Pointer Points to the p address.
* Q = & B; // * q is a pointer, and the result of & B is a pointer. The types of the two pointers are the same as those of the pointer, so this code is to assign a value to * q.
** Q = 34; // * the q result is what q points to. Here it is a pointer, that is, int *, and another operation is performed on this pointer, the result is an int-type variable. The address it occupies is the address pointed to by * q, that is, the address of B. Therefore, the purpose of this sentence is to assign a value to variable B.
Finally, you can verify the following:
#include
int main(){int a = 5; int b; int *p; int **q; printf("a = %d\n",a); p = &a; *p = 10; printf("a = %d\n",a); q = &p; *q = &b; **q = 34; printf("b = %d\n",b);}
Result:
a = 5a = 10b = 34
To understand these two operators, you must grasp the types of the results of the two operations and the types pointed.