How to create multidimensional array with an input variable?
I am trying to create a multi dimensional array with and input integer
This works
1 2 3 4 5 6 7 8 9 10
|
#include <stdio.h>
int main()
{
int n[9][9]={{0}};
printf("%d",n[8][8]);
return 0;
}
|
But this doesn't work
1 2 3 4 5 6 7 8 9 10
|
#include <stdio.h>
int main()
{
int m=9;
int n[m][m]={{0}};
printf("%d",n[m-1][m-1]);
return 0;
}
|
How should I pass array size to a multidimensional array as avariable?
This should work
1 2 3 4 5 6 7 8 9
|
#include <stdio.h>
int main()
{
const int m=9;
int n[m][m]={{0}};
printf("%d",n[m-1][m-1]);
return 0;
}
|
http://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new
Topic archived. No new replies allowed.