Carrying out some research on multidimensional arrays in C and how they are stored in memory, I came across this: " Does C99 guarantee that arrays are contiguous? ". The response to the upper voice states that “it should also be possible to iterate over the entire array using (char *)”, and then provides the following “valid” code:
int a[5][5], i, *pi;
char *pc;
pc = (char *)(&a[0][0]);
for (i = 0; i < 25; i++)
{
pi = (int *)pc;
DoSomething(pi);
pc += sizeof(int);
}
Then the poster says, "Doing the same with (int *) would be undefined behavior because, as said, an array [25] of int is not involved."
This line confuses me.
Why is using a char pointer a valid / specific behavior when substituting it with an integer pointer?
, .: (