How can I let a pointer assigned with a two dimensional array?
The following code won’t work.
float a1[2][2] = { {0,1},{2,3}};
float a2[3][2] = { {0,1},{2,3},{4,5}};
float a3[4][2] = { {0,1},{2,3},{4,5},{6,7}};
float** b = (float**)a1;
//float** b = (float**)a2;
//float** b = (float**)a3;
cout << b[0][0] << b[0][1] << b[1][0] << b[1][1] << endl;
a1is not convertible tofloat**. So what you’re doing is illegal, and wouldn’t produce the desired result.Try this:
This will work because two dimensional array of type
float[M][2]can convert tofloat (*)[2]. They’re compatible for any value ofM.As a general rule,
Type[M][N]can convert toType (*)[N]for any non-negative integral value ofMandN.