show() 的目的只是显示数组的元素。我的代码有什么问题?我的理解是,我们将单个元素的地址作为参数传递给 display(),然后将“x”的地址(存储元素的地址)传递给 show()。请帮忙!
#include <stdio.h>
void disp(int *);
void show(int *);
int main()
{
int i;
int marks[] = {55,65,89,78,74,77,45};
for(i=0;i<=6;i++)
{
disp(&marks[i]);
printf("%d \n", (&marks[i]));
}
return 0;
}
void disp(int *x)
{
show(&x);
}
void show(int *n)
{ printf("%d\n", *(*n));
}
最佳答案
当您在 disp()
中调用 show(&x)
时,您传递的是一个指向 int 的指针(因为 x
是一个指向 int 的指针),即使 show()
只接受一个指向 int 的指针。
您应该将 show()
中的参数从 int *n
更改为 int **n
以解决此问题。
关于c - 使用引用调用打印数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478130/