c - 传递指针数组并接收错误消息

标签 c arrays function pointers

嗨,我正在尝试将数组传递给指向函数的指针。我尝试用两种方法来做。我所做的第一种方法是将 *array 传递到函数中,但随后我收到下面的错误消息。于是我意识到了错误,改成了数组。但这让我想,为什么错误说期待双指针?这个错误现在让我有点困惑。有人可以解释一下吗。谢谢。

add(struct node *arrayy[],int value)
{
struct node *nodey = (struct node *)malloc(sizeof(struct node));
nodey->x=value;

if(arrayy[value]==NULL)
{
printf("I am not pointing to something...now I am hehehe\n");
 arrayy[value]=nodey;
}
else
{
printf("I already have a head..now my link is pointing at something\n");
arrayy[value]->link=nodey;
}   
}

struct node *array[10]={NULL};
add(*array,4);
add(array,4);

错误信息

note: expected ‘struct node **’ but argument is of type ‘struct node *’

最佳答案

你有

struct node *array[10]={NULL};

其类型为struct node *[](又名struct node **)。

这是 add 所期望的类型。

如果您取消引用它(使用 *array),您的类型将不再与 add 的原型(prototype)匹配。

关于c - 传递指针数组并接收错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18840169/

相关文章:

python - python参数实际上是参数的别名吗?

c++ - 将函数作为参数传递 CPP

c - 递归strcpy函数

c - Lua函数的返回值

c - 搜索字符串中的子字符串及其位置

Javascript 平均拆分数组

python - 嵌入 Python 时共享数组的最简单方法

php - 在 PHP 中将函数作为另一个函数的参数传递

c++ - 代码块 - 混合 c 和 c++ 文件

c# - 对如何使用 List<string>[] 感到困惑