When you declare an array of any dimension, the compiler sets aside a block of contiguous bytes, and uses the array name as a reference to the first element. So for example:
Code:
size_t
data[ 3 ][ 4 ];
The compiler allocates 3 * 4 * sizeof( size_t ) bytes on the stack, and since the array name is an reference to the first element, then ( ( size_t* )data ) == &data[ 0 ][ 0 ]. And because we're dealing with an array of arrays, ( ( size_t* )( data + 1 ) ) == &data[ 1 ][ 0 ]. Maybe this will make it more clear:
Code:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
size_t
data[ 3 ][ 4 ] =
{
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 }
},
size_in_bytes = sizeof( data ),
number_of_elements = size_in_bytes / sizeof( size_t ),
rows = size_in_bytes / sizeof( data[ 0 ] ),
columns = number_of_elements / rows,
row,
column;
printf( "size_in_bytes: %d \n", size_in_bytes );
printf( "number_of_elements: %d \n", number_of_elements );
printf( "rows: %d \n", rows );
printf( "columns: %d \n", columns );
printf( "address of data: %x \n", ( size_t* )data );
printf( "address of data + 1: %x \n", ( size_t* )( data + 1 ) );
for( row = 0; row < rows; ++row )
{
for( column = 0; column < columns; ++column )
{
printf
(
"<%x> data[ %d ][ %d ] = %d \n",
&data[ row ][ column ],
row,
column,
data[ row ][ column ]
);
}
}
return 0;
}