0

How did the output of this program become 1????

#include<iostrem.h> Using namespace std; Int main() { Cout<<(0==0) }

18th Jun 2018, 2:47 PM
Ashish Kumar Sahoo
Ashish Kumar Sahoo - avatar
10 Réponses
+ 2
0 is equal to 0, right so the expression 0==0 is true and returns "1", which is displayed by cout if it was 0==1, answer would be "0", cause 0 is not equal to 1
18th Jun 2018, 2:55 PM
‎ ‏‏‎Anonymous Guy
+ 2
the condition within the brackets is checked, which is true in c++, "1" represents true and "0" represents false so your program returns 1
18th Jun 2018, 2:50 PM
‎ ‏‏‎Anonymous Guy
+ 2
the condition is boolean, true meens 1 and false 0(does 0 equals 0)
18th Jun 2018, 2:56 PM
‎איתן מוצ'ה‎
‎איתן מוצ'ה‎ - avatar
+ 2
Trying to printing booleans and conditions will print 1 if the bool or condition is true otherwise 0
19th Jun 2018, 4:28 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 1
Thanks for clarify my doubts sreejith
18th Jun 2018, 3:26 PM
Ashish Kumar Sahoo
Ashish Kumar Sahoo - avatar
+ 1
see 0==0 evaluating to 1 because this expression is true the (==) matches the l-value to r-value and there l-value and r-value are equal
18th Jun 2018, 4:50 PM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar
+ 1
Thank you aveek
18th Jun 2018, 6:23 PM
Ashish Kumar Sahoo
Ashish Kumar Sahoo - avatar
0
How was it true??? Plz explain breafly...
18th Jun 2018, 2:51 PM
Ashish Kumar Sahoo
Ashish Kumar Sahoo - avatar
0
it is a logical expression which evaluates to true or false . When we say say the logical expression is true , the expression returns 1 and When we say say the logical expression is false , the expression returns 0
18th Jun 2018, 4:58 PM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar
0
if you want your result to be false then - #include <iostream> using namespace std; int main() { int x=0; if(x) { cout << 1; } else { cout << 0; } return 0; }
18th Jun 2018, 5:01 PM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar