If int *p holds the address 1000 and sizeof(int) is 4, what address does p + 3 hold?
Correct answer B. 1012
Explanation
Pointer arithmetic is scaled by the size of the pointed-to type. p + 3 means three ints further along, so the address increases by 3 * sizeof(int) = 12 bytes, giving 1012. Answer 1003 treats the pointer as a plain number. This scaling is what makes p[i] equivalent to *(p + i) for any element type.
Answer checked How we write and check questions
Discussion