ProgrammingHardTCS NQT · Infosys pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
int a[3] = {1, 2, 3};
int *p = a;
printf("%d ", *p++);
printf("%d ", *++p);
printf("%d", *p);
  1. A. 1 2 2
  2. B. 2 2 3
  3. C. 1 3 3
  4. D. 1 2 3

Correct answer: C. 1 3 3

*p++ uses p's CURRENT value first (a[0]=1), then increments p to point at a[1]. *++p increments p first (now at a[2]), then dereferences it, giving a[2]=3. The last *p reads the same current position again, a[2]=3. Output: 1 3 3.

More C Programming questions

Exams that ask this topic