預期的結果是打印與我們輸入的值相同的值,但輸出在第一行之後爲零。將數組傳遞給函數會改變它的值嗎?
#include<stdio.h>
void display(int *q, int);
int main() {
int i,j,n;
int d[50][50];
printf("Input the order\t");
scanf("%d", &n);
for (i=0;i<=(n-1);i++) {
for (j=0;j<=(n-1);j++) {
scanf("%d", &d[i][j]);
}
}
display (d, n);
}
void display (int *q, int r) {
int i,j;
for (i=0;i<r;i++) {
for (j=0;j<r;j++) {
printf("%d\t", *(q + i*r + j));
}
printf("\n");
}
}
編譯器在將它傳遞給'display'後不知道'd'的尺寸。 – goodvibration
搜索如何將多維數組傳遞給C中的函數。例如,請參閱[本文](http://stackoverflow.com/q/16943909/478288)。 – chrisaycock