array bound is not an integer constant before


Please Help me When ever
Getting error “array bound is not an integer constant before ']' token”
‪#‎include‬ <iostream>
using namespace std;
int maxr;
int maxc;
void readmatrix(int m[maxr][maxc]); // size depend upon input of maxr and
// maxc
main()
{
cout<<"enter Number of Row :";
cin>>maxr;
cout<<"enter Number of columb :";
cin>>maxc;
}
Move these

1
2
int maxr;
int maxc;


Inside main. Dont use globals.

Looking at your function, you want to send in a 2D array?

http://stackoverflow.com/questions/9446707/correct-way-of-passing-2-dimensional-array-into-a-function
Last edited on
you declare an array with index specified with non constant variable.
when you declare 2d array , the 2nd index must be specified only with a number or a constant variable.

closed account (SECMoG1T)
Wait , is your array dynamic or static ... most likely i'll guess it's static and if that's the case you're not allowed to do this

1
2
3
4
cout<<"enter Number of Row :";
cin>>maxr;
cout<<"enter Number of columb :";
cin>>maxc;


That only works for dynamic arrays, static arrays dimensions must be const values, so your variables in main should be like

1
2
const int maxr=/*some value*/; 
const int maxc=/*some value*/;
also, it is a good habit to call global var with scope operator
 
std::cin >> ::maxr;
Topic archived. No new replies allowed.