GateAI
Programming in C

GATE CSE 2017 Set 2 · Q54

NAT2 marksEasy

Time

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 _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 0 (±0)

Programming in C

Let us trace the execution of the program step by step:

  1. int m = 10;

    • Variable mm is initialized to 1010.

  2. n = ++m;

    • Pre-increment operator: mm is incremented first, so m=11m = 11.

    • Then nn is assigned the value of mm, so n=11n = 11.

  3. n1 = m++;

    • Post-increment operator: n1n1 receives the current value of mm, so n1=11n1 = 11.

    • Then mm is incremented, so m=12m = 12.

  4. n--;

    • Post-decrement: nn is decremented by 11, so n=10n = 10.

  5. --n1;

    • Pre-decrement: n1n1 is decremented by 11, so n1=10n1 = 10.

  6. n -= n1;

    • Compound assignment: n=n−n1=10−10=0n = n - n1 = 10 - 10 = 0.

  7. printf("%d", n); prints the value of nn, which is 0.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

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 C

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q54 · NAT

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.