Following code runs fine -
void func(int m[][2])
{
cout<<(m[0][0])<<endl;
}
int main()
{
// int x=2;
int m[2][2];
m[0][0] = m[0][1] = m[1][0] = m[1][1] = 5;
cout<<m[0][0]<<endl;
func(m);
}
But when I change main()
as follows -
int main()
{
int x=2;
int m[x][x];
m[0][0] = m[0][1] = m[1][0] = m[1][1] = 5;
cout<<m[0][0]<<endl;
func(m);
}
I get the error message -
try.cpp:16:11: error: cannot convert ‘int (*)[(((long unsigned int)(((long int)x) + -0x00000000000000001)) + 1)]’ to ‘int (*)[2]’ for argument ‘1’ to ‘void func(int (*)[2])’
Also, the following runs fine -
int main()
{
int x=2;
int m[x][x];
m[0][0] = m[0][1] = m[1][0] = m[1][1] = 5;
cout<<m[0][0]<<endl;
//func(m);
}
Can anyone explain the issue here? Thanks.