845 views
0 0 votes

answer the output

#include <stdio.h>

int main() {
int x=0;
x++;
if(--x){
        x=x++;
        if(x){
                printf("hello");
        }else{
                printf("%d",x);
        }
}else{
        x=x+5;
        if(x){
                printf("i win x times");
        }
        else{
                printf("you win 5 times");
        }
}
        return 0;
}

 

3 Answers

Best answer
4 4 votes
First  $X=1$  after post increment and in if condition it will become  $X=0$ so its False then it comes in else part $X=5$  So in if Condition it's True coz in C Programming  Except $0$ every other number is true either it positive or negative So it will print "i win x times"
• selected by
1 1 vote

After second line in main function x will become 1, but in next line their is pre-increment so x will become 0, and if(0) is false. So if statement will not get executed.
Now in the else block their is 

 x =x+5 which makes x=5


so the nested if(x) will be true and get executed.  Hence I win x times will get printed.

Position:
Show:

Related questions

0 0 votes
2 2 answers
3.7k
3.7k views
Lakshman Bhaiya asked Apr 21, 2018
3,711 views
Q) What is the output of the following C Program fragment#include<stdio.h>int main(){int a = 4, b = 3;printf("%d",a+++++b);return 0;} A) 7 B) 8 C) 9 ...
0 0 votes
0 0 answers
921
921 views
Lakshman Bhaiya asked Mar 1, 2018
921 views
#include<stdio.h int main() { int a = 15; printf("%d\n",++a); printf("%d\n",a++); printf("%d\n", a); printf("%d\n",a ); return 0; }16,16,16,1615,13,15,1516,15,14,1416,16,...
0 0 votes
0 0 answers
601
601 views
rahul sharma 5 asked Aug 25, 2017
601 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?
3 3 votes
1 answers 1 answer
4.6k
4.6k views
Sandeep Suri asked Aug 1, 2017
4,631 views
#include <stdio.h>int main(){ int x = 3;if (x == 2);x = 0;if (x == 3) x++;else x += 2;printf("x = %d", x);return 0;}