Consider the following C Program. #include 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 …
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2017 Set 2 · Q54
Time
#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 _________.Your answerNumerical answer
Solution
Official answer: 0 (±0)
Programming in CLet us trace the execution of the program step by step:
int m = 10;
Variable is initialized to .
n = ++m;
Pre-increment operator: is incremented first, so .
Then is assigned the value of , so .
n1 = m++;
Post-increment operator: receives the current value of , so .
Then is incremented, so .
n--;
Post-decrement: is decremented by , so .
--n1;
Pre-decrement: is decremented by , so .
n -= n1;
Compound assignment: .
printf("%d", n); prints the value of , which is 0.
Try the question first, then check your work.
Examiner trap
Recall the difference between pre-increment/decrement (++x, --x) and post-increment/decrement (x++, x--). Trace each variable's value line by line.
This Programming in C previous year question is Q54 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 17 of them are 2-mark NAT questions like this one, and GATE CSE 2017 Set 2 has 6.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.