使用预递增运算符指向指针取消引用的指针
Pointer to pointer dereference with pre-increment operator
以下程序给出的输出为 17,29,45;我不明白 **++pp;
是什么意思。谁能详细解释一下程序。
#include <stdio.h>
int main() {
static int a[] = {10, 22, 17, 29, 45};
static int *p[] = {a, a + 2, a + 1, a + 4, a + 3};
int **pp = p;
**++pp;
printf("%d %d %d", **pp, *pp[3], pp[0][2]);
}
在您的代码中,**++pp;
与 * (* ( ++pp));
相同。它首先递增指针,然后引用两次(第一个解引用结果是指针类型,详细说明)。
但是,解引用得到的值并没有被使用。如果您启用了编译器警告,您将看到类似
的内容
warning: value computed is not used
你可以去掉解引用,没用的。
以下程序给出的输出为 17,29,45;我不明白 **++pp;
是什么意思。谁能详细解释一下程序。
#include <stdio.h>
int main() {
static int a[] = {10, 22, 17, 29, 45};
static int *p[] = {a, a + 2, a + 1, a + 4, a + 3};
int **pp = p;
**++pp;
printf("%d %d %d", **pp, *pp[3], pp[0][2]);
}
在您的代码中,**++pp;
与 * (* ( ++pp));
相同。它首先递增指针,然后引用两次(第一个解引用结果是指针类型,详细说明)。
但是,解引用得到的值并没有被使用。如果您启用了编译器警告,您将看到类似
的内容warning: value computed is not used
你可以去掉解引用,没用的。