我可以肯定的告诉你,不可能在程序运行的时候决定一个
二维数组的大小,因为数组的大小是
在编译时就决定了的,不是在运行时,如果是一维的通过某些方法还可以办到,二维的就不可
能了,拿一维的来说:
polly@nowthen:~$ cat test.c
#include <
stdio.h>
#include <
stdlib.h>
struct test {
int num;
int arr[0];
};
int main()
{
struct test *temp;
int n = 0;
scanf("%d", &n);
if(n > 0) {
temp = (struct test*)malloc(sizeof(struct test)+n*sizeof(int));
temp->num = n;
int i = 0;
for(; i<temp->num; i++) {
temp->arr[i] = i;
}
for(i=0; i<temp->num; i++) {
printf("element %d = %d\n", i, temp->arr[i]);
}
}
return 0;
}
polly@nowthen:~$ gcc -Wall test.c -o liu <---编译
polly@nowthen:~$ ./liu <---运行
9 <---输入数组维数
element 0 = 0
element 1 = 1
element 2 = 2
element 3 = 3
element 4 = 4
element 5 = 5
element 6 = 6
element 7 = 7
element 8 = 8
polly@nowthen:~$
就上面的C语言标准也是不支持的,多维数组的办不到,一维的也尽量少用。