The difference is: 1. *p represents the content stored in the memory address pointed by this pointer, p represents the name of a pointer variable; 2. *p is generally a variable or constant that is consistent with the pointer type, p The output is a hexadecimal number; 3. *p tells the program to retrieve data from that address, and p stores the address.
The operating environment of this tutorial: Windows 7 system, C 17 version, Dell G3 computer.
In C language, *p and p are commonly used in pointers to represent a pointer variable. The difference between *p and p is:
1. The meanings are different
* p represents the content stored in the memory address pointed to 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 outputs a hexadecimal number and outputs the address of a pointer.
3. Different functions
*p Let the program go to that address to retrieve the data.
p stores the address.
Examples:
1,
int a[5]={1,2,3,4,5}; int *p=a;//这是在定义指针变量p的同时就直接给它初始化,即把数组a的首地址赋给它。
2,
int a[5]={1,2,3,4,5}; int *p;//声明指针变量p p = a;
Extended information
(*p) operation is an operation that returns the value of p as the value of the address space. (&p) is an operation that returns the address opened when p was declared. You can use assignment statements to assign values to memory addresses.
Example:
int *p; p=2003H; *p=3000H
Result:
**p=*(*(p))=*(*(2003H))=*(3000H)=3000H。 &&p=&(&(p))=&(3001H),此时出错了,3001H 是个常数无法存放地址。 *&p=*(&(p))=*(3001H)=2003H,也就是*&p=p。
Recommended tutorial: "C#"
The above is the detailed content of What is the difference between *p+1 and *(p+1). For more information, please follow other related articles on the PHP Chinese website!