[問題] 傳入一個struct的陣列至function????

看板C_and_CPP (C/C++)作者 (mathematic)時間16年前 (2009/11/18 21:37), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/1
( *[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

11/18 21:42, , 1F
把10拿掉
11/18 21:42, 1F
※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:46)

11/18 21:46, , 2F
沒用..
11/18 21:46, 2F
※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:49)

11/18 21:53, , 3F
check(student);
11/18 21:53, 3F

11/18 21:54, , 4F
指標的概念要弄清楚, 請去了解 &student[10] 的意義
11/18 21:54, 4F
11/18 21:54 ※ 編輯: mahoihei 來自: 116.49.84.46 (11/18 21:55)

11/18 21:56, , 5F
謝謝各位大大解決了我做了一星期的問題....
11/18 21:56, 5F
文章代碼(AID): #1B0_Yiwm (C_and_CPP)
文章代碼(AID): #1B0_Yiwm (C_and_CPP)