我有一個數組並希望將它傳遞給一個函數,該函數需要指針數組作爲參數,當我通過引用傳遞它時,它只給出第一個元素該陣列。我究竟做錯了什麼?這裏是我的代碼:無法讀取第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