Pardon the confusing question title, but I was unsure how to phrase it more clearly.
In C, accessing an array out of bounds is classified as undefined behavior. However, array elements are guaranteed to be laid out contiguously in memory, and the array subscript operator is syntactic sugar for pointer arithmetic (e.g x[3] == *(x + 3)
). Therefore, I would personally expect the behavior of the code below to be well-defined:
int array[10][10];
int i = array[0][15]; // i == array[1][5]?
If my interpretation of the standard is correct, this would be undefined behavior. Am I wrong?