ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: B. 11 20

Postfix ++ yields the old pointer value, so *p++ reads 10 and then moves p to a[1]. The sum 10 + 1 gives x = 11 and the next read is 20.

More C Programming questions

Exams that ask this topic