edited by
11,941 views
25 votes
25 votes

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 ______

edited by

7 Answers

Best answer
35 votes
35 votes
  • $m = 10; \quad \; \qquad \qquad \overset{m}{\boxed{10}}$
  • $n=\text{++}m; \qquad\qquad  \overset{n}{\boxed{11}}  \quad\overset{m}{\boxed{11}}$
  • $n1=m\text{++}; \; \;\quad \qquad  \overset{n1}{\boxed{11}}  \quad\overset{m}{\boxed{12}}$
  • $n\text{ --}; \; \; \;\qquad \qquad \qquad \overset{n}{\boxed{10}}$
  • $\text{-- }n1; \;\qquad \qquad \qquad \overset{n1}{\boxed{10}}$
  • $n\text{ -= }n1; \; \;\;\; \qquad \qquad \overset{n}{\boxed{0}} \quad(\because n = n-n1 = 10-10=0)$

So, 

printf("%d", n); // prints 0.

Hence, answer is 0.

edited by
4 votes
4 votes
Final answer is expected to be zero.

Correct me if i am wong!!
Answer:

Related questions

70 votes
70 votes
13 answers
1
Madhav asked Feb 14, 2017
27,897 views
Consider the following C program.#include<stdio.h #include<string.h int main() { char* c="GATECSIT2017"; char* p=c; printf("%d", (int)strlen(c+2[p]-6[p]-1)); return 0; }T...
39 votes
39 votes
5 answers
2
Madhav asked Feb 14, 2017
9,634 views
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:$$\begin{array}{|l|l|}\hline \text{P. Syntax t...
25 votes
25 votes
7 answers
3
khushtak asked Feb 14, 2017
6,900 views
Match the algorithms with their time complexities:$$\begin{array}{|l|l|}\hline \textbf{Algorithms} & \textbf{Time Complexity} \\\hline \text{P. Tower of Hanoi with $n$...
30 votes
30 votes
11 answers
4
Madhav asked Feb 14, 2017
9,663 views
Consider the following function implemented in C:void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); }The output of invoking $...