ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[3] = {1, 2, 3};
    int *p = a;
    printf("%d ", *p++);
    printf("%d ", *p);
}
  1. A. 1 2
  2. B. 2 2
  3. C. 1 1
  4. D. 2 3

Correct answer: A. 1 2

Postfix ++ binds tighter than unary *, so *p++ means *(p++): it dereferences p first (giving a[0]=1) and only afterwards advances p to a[1]. The second printf then reads the now-current a[1]=2.

More C Programming questions

Exams that ask this topic