Difference: 1. The meanings are different. "*p" represents the content stored in the memory address pointed by this pointer. "p" represents the name of a pointer variable, which refers to the memory address pointed by this pointer variable. . 2. The output formats are different. "*p" usually outputs a variable or constant of the same type as the pointer. "p" outputs a hexadecimal number and the address of a pointer. 3. The functions are different. "*p" tells the program to go to that address to retrieve data, and "p" is used to store the address.
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
*p
, p
In C language, *p and p are commonly used A pointer represents a pointer variable.
If you want to use pointers, you need to first understand addresses and data: you can imagine that there are many boxes, each box has a corresponding number, that number is called "address", and the stuff in the box is called "data" .
p is a pointer variable, used to store the address. You can think of it as the number of the box mentioned above. "*" is the dereference operator. You can think of it as opening the box. p means opening p. No. box and take out the data inside.
To put it simply, remember, p stores the address, and p tells the program to go to that address to retrieve data.
In C language, the * sign has three uses, namely:
The multiplication sign is used for multiplication operations, such as 5*6.
Declare a pointer, used when defining pointer variables, such as int *p;.
Indirect operator, obtains the value in the memory pointed to by the pointer, such as printf("%d",*p);.
*p
and p
in C language1. The meanings are different.
*p
represents the content stored in the memory address pointed by this pointer.
p
represents the name of a pointer variable, which refers to the memory address pointed to by the pointer variable.
2. The output format is different
*p
is generally a variable or constant that is consistent with the pointer type.
p
The output is a hexadecimal number and the address of a pointer.
3. Different functions
#*p
Let the program go to that address to retrieve the data.
p stores the address.
#include <stdio.h> int main(void){ int x=3; int *p,*q; p=&x,q=&x; printf("%d\n",*p++); printf("%d\n",(*q)++); printf("%d\n",x); }
The output result is: 3, 3, 4;
Explanation:
*p
and **p
Differenceint *p
: Level one pointer, indicating that the address pointed to by p stores an int type value
int * *p
: Second-level pointer, indicating that the address pointed to by p stores a pointer to type int (that is, the address pointed to by p stores a first-level pointer to int)
For example:
int i=10; //定义了一个整型变量 int *p=&i; //定义了一个指针指向这个变量 int **p1=&p; //定义了一个二级指针指向p指针
Then the way to extract the value of 10 is:
printf("i=[%d]\n",*p); printf("i=[%d]\n",**p1);
C Video Tutorial"
The above is the detailed content of What is the difference between *p and p in C language. For more information, please follow other related articles on the PHP Chinese website!