#include<stdio.h>
Funtions prototypes
int functiondouble(int b);
void notreturnanything(int a, int b);
void byreference(int *b);
void receivevector(int v[]);
void recievematrix(int m[][1]);
int main() {
int c;
printf("%d\n",functiondouble(5));
notreturnanything(3,9);
c = 0;
byreference(&c);
printf("%d\n",c);
int a[10], b[3][4];
receivevector(a);
recievematrix((int)b); // <----- warning: passing argument 1 of 'recievematrix' from incompatible pointer type [enabled by default]|
return 0;
}
int functiondouble(int b) {
int a;
a = 2*b;
return a;
}
void notreturnanything(int a, int b) {
printf("%d\n",a+b);
}
沒問題。這兩個功能沒有問題。他們收到一個沒有問題的價值。從不兼容指針類型傳遞參數1'recievematrix'
void byreference(int *b) {
*b = 7;
}
void receivevector(int v[]) {
scanf("%d", &v[0]);
}
void recievematrix(int m[][1]) {
scanf("%d", &m[1][1]);
}
這是一個證明如何在C中工作的數組,但拉錯誤而不是錯誤在哪裏。
爲了代碼的可讀性,建議爲函數和變量名稱使用'駱駝'情況 – user3629249 2015-03-31 22:16:01
應始終檢查scanf()函數的返回值和函數系列,以確保操作在此調用上成功 – user3629249 2015-03-31 22:18:53
(也許是類似的調用)'recievematrix((int)b);'被調用的函數需要一個指向int的指針,而不是int。也許使用:'recievematrix((int *)b);' – user3629249 2015-03-31 22:22:58