Consider the following C program. #include<stdio.h> int main () { int m=10;…

2017

Consider the following C program.

#include<stdio.h> int main () { int m=10; int n, n1; n=++m; n1=m++; n--; --n1; n-=n1; printf(“%d”, n); return 0; }

The output of the program is ______

Attempted by 386 students.

Show answer & explanation

Correct answer: 0

Evaluate the program step by step, tracking the values of m, n, and n1.

  • Start with m = 10.

  • n = ++m; pre-increment increments m to 11, then n is set to 11.

  • n1 = m++; post-increment sets n1 to the current m (11), then increments m to 12.

  • n--; post-decrement decreases n from 11 to 10.

  • --n1; pre-decrement decreases n1 from 11 to 10.

  • n -= n1; compute n = 10 - 10 = 0.

Final output printed by printf: 0

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir