作者mahoihei (mathematic)
看板C_and_CPP
標題[問題] 傳入一個struct的陣列至function????
時間Wed Nov 18 21:37:46 2009
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: 不能傳址呼喚一個struct的陣列
程式跑出來的錯誤結果:只能傳值...
開發平台: (例:Dev-pas
有問題的code:
#include <stdio.h>
#include <conio.h>
struct test{
int mark;
};
int check(struct test[10]);
int main(void){
struct test student[10];
student[1].mark=1;
check(&student[10]);
printf("%d\n", student[1].mark);
printf("%d\n", check(&student[10]));
getch();
return 0;
}
int check(struct test data[10]){
data[1].mark=3;
printf("check-pt\n");
return data[1].mark;
}
result of program:
check-pt
1
check-pt
3
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 116.49.84.46
1F:推 Bencrie:把10拿掉 11/18 21:42
※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:46)
2F:→ mahoihei:沒用.. 11/18 21:46
※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:49)
3F:推 ledia:check(student); 11/18 21:53
4F:→ ledia:指標的概念要弄清楚, 請去了解 &student[10] 的意義 11/18 21:54
11/18 21:54
※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:55)
5F:→ mahoihei:謝謝各位大大解決了我做了一星期的問題.... 11/18 21:56