I am solving questions on pointers and arrays in C I think I get the concept of but I want to know if I messed up here is the original question, my answers are down below and my reasoning for them
Assume that the variables declared below are stored at the following locations. Show what value is stored as a result of each of the following statements. Assume that each statement uses the values stored by the previous statements.
int *p, *q, *r;
int a = 10; b = 25;
int c[4] = {6,12,18,24};
address variables
5000 p
5004 q
5008 r
500C a
5010 b
5014 c[0]
5018 c[1]
501C c[2]
5020 c[3]
1. p = c;
2. q = &a;
3. r = p + 2;
4. c[1] = *p;
5. c[2] = *(p + 2);
6. c[3] = *p + 2;
7. *r = *q;
8. r = q;
9. p = &c[0];
10. p++;
My answers
1.5014 because p is a pointer so it points to c, which points to c[0]'s address which is 5014
2.500c because q is set to point to a's address
3.5016 because p is now 5014, 5014+2 = 5016 (I'm not sure what this would point to since 5016 is not on the address list)
4.6 , p points to address c[0] and that element is 6
5.5016 , I don't know how this would work, you would add 5014 + 2 = 5016 but that doesn't point to anywhere according to the addresses
6.8 , p points to address c[0] where 6 is stored, 6+2 = 8
7.500c , r is set to point at q which is pointing to a's address
8.10 , q points to a which is 10 (I don't understand the difference with this one and the #7, maybe the answers should be reversed)
9). 5014, p is set 5[0]'s address
10.5015, p is incremented
Can anyone tell if I messed up?