+ 1

Here why am I getting my output as 0 only?!?

#include <stdio.h> int main() { int x=1; if(x) x=0; if(x) x=2; printf("%d",x); return 0; }

14th Apr 2018, 12:53 PM
Khushboo Gupta
Khushboo Gupta - avatar
3 ответов
0
if (1) cout << "ok!"; if (0) cout << "nope... "; edit: brains' answer is better. He actually explains it and I just gave an example. You should mark his answer as best ^^
14th Apr 2018, 12:57 PM
Alex
Alex - avatar
+ 2
thanks,I get it now😊
14th Apr 2018, 1:00 PM
Khushboo Gupta
Khushboo Gupta - avatar
0
int x=1 //x is true if(x)evaluates to true x=0//x becomes 0 if(x)evaluates to false since x is 0 x=2 //this block of code is not run then x is still is 0
14th Apr 2018, 12:57 PM
᠌᠌Code X
᠌᠌Code X - avatar