I just took an exam for my Computer Science class. On the exam, there was an 2-D int array and we were asked to compute the values. I thought I understood pointer arithmetic, but I got half of them wrong, so I was hoping someone here could explain it better.
I've watched a few Youtube videos and looked at multiple different lecture slides/notes and am still having trouble grasping the concept when it is a 2-D array, I understand a one dimensional one.
int a[2][3] = {{30,40,50} , {60,70,80}};
show the results of the following:
1. a =
2. a[0] =
3. a + 1 =
4. a[0][0] + 1 =
5. *a[0] + 1 =
6. *(a[0] + 1) =
We are to assume that the addresses start at 0x100.
I gave the following answers:
1. a = 0x100
2. a[0] = 0x100.
3. a + 1 = 0x112.
4. a[0][0] + 1 = 0x112.
5. *a[0] + 1 = 11.
6. *(a[0]+1) = 0x104.
........................................................................
I got 3 half credit for 3, 4 wrong, and 6 wrong.
If I could change my answer now, I have no idea why 3 is wrong, no idea why 4 is wrong, and I believe 6 would be 40.