int main()
{
int arr[3] = { 1,2,3 };
printf("%p\n", arr);
printf("%p\n", arr + 1);
printf("%p\n\n", arr + 2);
printf("%p\n", &arr[0]);
printf("%p\n", &arr[1]);
printf("%p\n", &arr[2]);
return 0;
}
output:
000000A3344FF7E8
000000A3344FF7EC
000000A3344FF7F0
000000A3344FF7E8
000000A3344FF7EC
000000A3344FF7F0
I don't understand the logic behind the operation arr + 1. Since arr is 000000A3344FF7E8, I thought it was going to add 1 resulting in 000000A3344FF7E9. But instead in reality it adds 1*sizeof(element) == 4 resulting in 000000A3344FF7EC.
So my question is, how does the compiler understand pointer arithmetic arr + 1 as not just number addition? And could you elaborate specifically on what arr + 1 is doing.