The GATE Grind

GATE 2017 CS (CS2) – Question 64

Programming and Data Structures · Programming in C · 2 marks · Numerical answer

Find the C program output.

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

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 0.0 to 0.0

Explanation

After n=++m, m=11 and n=11. Postincrement assigns old m=11 to n1, then m becomes 12. Decrementing n and n1 makes each 10. Finally n-=n1 gives 10−10=0, so the program prints 0. These changes occur in separate full expressions.

More Programming in C questions

All Programming in C questions →