I've been thinking about this for about a month now and have no resolution.
int* (*arr)[5];
int n[5] = {0, 1, 2, 3, 4};
int* arr_l2[5] = {&n[0], &n[1], &n[2], &n[3]};
arr = &arr_l2;
printf("%d \n", *((*arr)[2])); // outputs 2, accessed using n[2]
printf("%p \n", *((*arr)+2)); // outputs address 0x7ffd793894e8, stack address holding value 2
Consider this code. Why would the second printf() not output 2 with the dereferencing schemes used? To me, it seems to make intuitive sense that it would because using pointer arithmetic:
*(arr + 2) is the equivalent of arr[2]
Additionally, what exactly is a & reference? I only realized today that reference parameters may be used as the variable itself, and are not like pointers, which must be dereferenced. A former professor of mine had said that pointers and references are the same, but this is obviously not true.
Could I please get a simple but thorough explanation on the number of dereferences, the reference operator, and this subtle mismatch?