gpt4 book ai didi

c - 在函数中取消引用数组指针

转载 作者:太空宇宙 更新时间:2023-11-04 06:34:09 25 4
gpt4 key购买 nike

如何引用指向数组的指针以获取存储在其中的值?例如:

void testFunction(int **test){
printf("%d", *test[1]);
}

int main()
{ int test[10];
test[1] = 5;
testFunction(&test);
return 0;
}

我得到一个错误。谁能解释一下?

最佳答案

How do you deference a pointer to an array to get the value stored in it?

您使用 * 运算符,就像每个指针一样。 (哦,注意运算符优先级!)

void foo(int (*arr)[5])
{
printf("%d\n", (*arr)[0]);
}

int main()
{
int arr[5] = { 0, 1, 2, 3, 4 };
foo(&arr);
return 0;
}

关于c - 在函数中取消引用数组指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16926393/

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