Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.