我有一个数组并希望将它传递给一个函数,该函数需要指针数组作为参数,当我通过引用传递它时,它只给出第一个元素该阵列。我究竟做错了什么?这里是我的代码:无法读取第0个元素的指针数组元素的指针
#include <stdio.h>
#include <stdlib.h>
struct abc{
int a;
};
void a(struct abc* j[]){
printf("%d\n",j[1]->a);
}
int main()
{
struct abc* k = malloc(2 * sizeof(struct abc));
k[0].a = 2;
k[1].a = 3;
a(&k);
return 0;
}
在此先感谢
@BLUEPIXY thanx,this works,can you explain me why [1] - > a doesnt? – user3734435 2015-04-03 18:30:45
@BLUEPIXY感谢好友解释得好! – user3734435 2015-04-03 18:39:32
@BLUEPIXY感谢伙计,我明白了,你能否让它成为答案,以便其他人可以更容易地找到解决方案,如果有人有问题,我有 – user3734435 2015-04-03 19:05:32