What is printed by this C code: int a = {1, 5, 9}; int *p = a; int v = *p++; printf(“%d %d”, v, *p);?
Correct answer D. 1 5
Explanation
Postfix ++ binds more tightly than unary *, so *p++ means *(p++): it yields the element p pointed to before the increment, 1, and then advances p to a[1]. So v is 1 and *p is now 5. Answer 2 5 would come from (*p)++, which increments the value and not the pointer. The idiom *p++ is common in loops that walk through arrays.
Answer checked How we write and check questions
Discussion