Hello everyone,
I am just interested in the following sample, how compiler maps one dimensional int pointer array to two dimensional int array so perfect. E.g. p [3][3] maps to the 33th element and p [0][9] maps to the 9th element.
How does the compiler do the internal mapping of one dimensional int pointer array (variable p) and the two dimensional int array (variable buffer)?
Code:
int main (int argc, char** argv)
{
int (*p) [10];
int buffer [10][10];
int tmp;
int i = 0;
int j = 0;
// to initialize
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
buffer [i][j] = i * 10 + j;
}
}
p = &buffer;
tmp = p [3][3]; // tmp = 33
tmp = p [0][9]; // tmp = 9
return 0;
}
thanks in advance,
George