可以参照下列链接,一个大神
http://blog.csdn.net/morewindows/article/details/7664479
另一种思路,使用一维数组的访问模拟二维数组的访问
#include <stdio.h>
#include <stdlib.h>
int main() {
int row, col;
row = 3;
col = 4;
int *a;
a = (int *)malloc(row * col * sizeof(int));
for (int i=0; i<row; ++i) {
for (int j=0; j<col; ++j) {
a[i*col + j] = j+1;
}
}
for (int i=0; i<row; ++i) {
printf("%d: ", i+1);
for (int j=0; j<col; ++j) {
printf("%d ", a[i*col + j]);
}
putchar('\n');
}
free(a);
return 0;
}