ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int a[] = {1, 2, 3}, *p = a;
int x = ++*p++;
int y = *p++ * 10;
printf("%d %d %d %d", x, y, a[0], *p);
  1. A. 2 20 2 3
  2. B. 3 20 1 3
  3. C. 2 30 2 3
  4. D. 2 20 1 3

Correct answer: A. 2 20 2 3

++*p++ parses as ++(*(p++)): the postfix ++ moves p to a[1] but the dereference uses the old address, so a[0] becomes 2 and x = 2. Then *p++ reads a[1] = 2 (y = 20) and moves p to a[2] = 3. '2 20 1 3' forgets that a[0] itself was incremented.

More C Programming questions

Exams that ask this topic