The difference between the C language * p, and p & p of difference, * p ** p and the

Transfer from the difference in C * p, p & p's and

Preface:

You need to understand and address data, you can imagine there are a lot of boxes, each box has a corresponding number, that number is called the "Address" box and put something called "data."
The above paragraph to understand the difference between * p and p is not hard to explain.
p is a pointer variable, used to store the address, you can think of a number of the above mentioned case, "*" is the dereference operators, you can understand it to open the box, p is the number p box open, remove the inside data.
In simple terms, you remember, it is the address of p, and
p is the program to go to that address to retrieve data.

to sum up:

Suppose we define a pointer p.
They will often use the three symbols:
1, the p-;
2, the p-*;
3, & the p-;
beginners often feel very confused, in the end what these three symbols represent?

p is the name of a pointer variable indicates the memory address of the pointer variable points to, if you use% p to output, it will be a hexadecimal number.

* P represents the contents of the memory address stored in this pointer, and a generally uniform and constant or variable pointer type. As we know, a & address operator, p & fetch address is the pointer p.

Wait, how again address it in the end and p What is the difference?

Difference: p but also a pointer variable, since it is variable, the compiler sure you want to allocate memory, as the program defines a variable of type int i, the compiler you want to assign the same piece of memory space.

& p says compiler for the memory address of the variable distribution of p, and because p is a pointer variable, this special status doomed it to a memory address that points to another programmer in accordance with the procedures required
to point to a memory address, the it points to the memory address indicated by p. Moreover, the content of the address pointed to by p says with a * p.

** p * p and the difference

int * p: a pointer indicating the address pointed to by p which is stored a value of type int
int ** p: two pointer indicating the address pointed to by p which is stored a pointer to a pointer of type int (i.e. p points to the address of which is stored a pointer to a pointer to an int)
For example:
int I = 10; // definition of an integer variable
int * p = & i; // define a pointer to the variable
int ** p1 = & p; // pointer to define a two pointer p
then taken as the value of mode 10:
the printf ( "I = [D%] \ n-", * p);
the printf ( "I = [D%] \ n- ", ** p1);

Guess you like

Origin blog.csdn.net/weixin_43115440/article/details/93475460