Possible Duplicate:
May I treat a 2D array as a contiguous 1D array?
Consider the following code:
int array2d[10][10];
int *array1d = array2d[0];
I never heard of an implementation where it wouldn't work, but is it legal to access and manipulate array2d
via array1d
? Which section of the standard allows this? Is there anything in the standard preventing implementations from inserting extra space or padding between each of the second level arrays (not that its needed, but still)?
Bonus question: Is there a way to access array2d
as an int[100]
which does not require a reinterpret_cast
or a C-style one?