I was messing around with double pointers last day and this behaviour wasn't not expected:
int main(){
char arr[2][10] = {"Burger", "Pizza"};
char **ptr = (char**) arr;
printf("%p %p\n", arr, ptr); // first printf
printf("%p %p\n", arr+1, ptr+1); // second
printf("%p %p\n", arr[0], *ptr); // third
puts(ptr);
puts(ptr+1);
}
In this example, I've assumed that, arr
and ptr
points to the same address and this assumption was confirmed correct with the first printf:
0x7fffe4fd5010 0x7fffe4fd5010
Secondly, I've assumed that, arr+1
and ptr+1
, also both points to the same address, but when I tried running it, the output wasn't:
0x7fffe4fd501a 0x7fffe4fd5018
How could this be? Is there something I'm missing with the C programming language?