ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int main(void) {
    int a = 5;
    int b = a;
    b = b + 10;
    int *p = &a;
    *p = *p + 100;
    printf("%d %d", a, b);
}
  1. A. 105 15
  2. B. 5 15
  3. C. 105 5
  4. D. 15 105

Correct answer: A. 105 15

b is an independent copy of a's original value (5), so b=5+10=15 never affects a. Separately, modifying a through pointer p (*p = *p+100) changes a directly to 5+100=105. Final: a=105, b=15.

More C Programming questions

Exams that ask this topic