Home  >  Article  >  What is the difference between *p+1 and *(p+1)

What is the difference between *p+1 and *(p+1)

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-09 11:54:1021380browse

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.

What is the difference between *p+1 and *(p+1)

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;

What is the difference between *p+1 and *(p+1)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn