ProgrammingHardTCS Digital · Cognizant

What does this program print? #include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int *p = a + 1; int v = *p++; int w = ++*p; printf("%d %d %d %d", v, w, a[1], a[2]); return 0; }

  1. A. 20 21 21 30
  2. B. 20 31 21 31
  3. C. 30 31 20 31
  4. D. 20 31 20 31

Correct answer: D. 20 31 20 31

*p++ yields 20 and moves p to a[2]. ++*p then increments the pointed value, so a[2] becomes 31 and w is 31, while a[1] stays 20.

More C Programming questions

Exams that ask this topic