我试图编写一个程序来打印一个未指定维度的多维矩阵,我发现当我写入
void**
行时,该程序无法运行。这是为什么?
#include<stdio.h>
#include<stdlib.h>
int main(){
int n=0;
printf("The size of matrix\n");
scanf("%d",&n);
int ** rows; //it doesnt work with void
rows=malloc(n * sizeof(int*));
int i,j;
for(i=0;i<n;i++){
rows[i]=malloc(n*sizeof(int));
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
rows[i][j]=i+j;
printf("%d",rows[i][j]);
}
printf("\n");
}
return 0;
}
当我写 void**
时不运行
这是因为您无法取消引用
void
指针,因为它没有引用任何类型。