gpt4 book ai didi

c - 指向指针作为函数参数的指针

转载 作者:行者123 更新时间:2023-11-30 18:33:04 24 4
gpt4 key购买 nike

我有以下代码:

#include <stdio.h>
#include <stdlib.h>

int f(int x, int *py, int **ppz) {
int y, z;
**ppz += 1;
z = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}

int main(void) {
int c = 4;

printf("f(): %d\n", f(c, &c, &&c));
printf("c: %d\n", c);
return EXIT_SUCCESS;
}

我怎样才能正确访问**ppz,因为我收到一条错误消息:“标签'c'已使用,但未定义”。

最佳答案

int** 是指向 int* 的指针。您需要创建一个 int* 类型的变量,以便能够将指针传递到某个地方。这是你应该做的:

int main(void) {
int c = 4;
int* pc = &c;

printf("f(): %d\n", f(c, pc, &pc));
printf("c: %d\n", c);
return EXIT_SUCCESS;
}

请参阅 @ikegami 的回答,了解如何正确使用指向指针的指针。

关于c - 指向指针作为函数参数的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59511923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com