Skip to content
GATEiit

GATE CSE 2017 Session 2 Q64: Output of pre/post increment and decrement program

Syllabus topic: Programming in C

Question

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

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 0 (official GATE 2017 final answer key)

Concept used: Pre-increment changes the variable before its value is used; post-increment uses the old value and then increments.

Concept notes

Loading notes…

First step: Track the values of m, n and n1 line by line, noting which value each increment expression returns.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Programming in C

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key