#include<stdio.h>
int main()
{
int m;
int n;
int rows,columns;
int **array2D;
array2D=new int*[m];
for(int i=0;i<m;i++)
{
array2D[i]=new int[n];
}
printf("Please input the number of rows you want to set as the length of your array\n");
scanf("%d",&rows);
printf("Please input the number of column you want to set as the width of your array\n");
scanf("%d",&columns);
printf("Please input %d numbers to set as the content of your array\n",rows*columns);
for(int m=0;m<=rows-1;m++)
{
for(int n=0;n<=columns-1;n++)
{
scanf("%d",&array2D[m][n]);
}
}
for(int i=0;i<=m;i++)
{
delete array2D[i];
}
delete array2D;
return 0;
}
运行结果:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Process exited after 3.181 seconds with return value 3
请按任意键继续. . .