0

how if(a) works ?

a=0; if(a) cout<<1; else cout<<2; when a=0 outputs is 2 but if a =! 0 output is 1 can someone explain me how if makes this decision? https://code.sololearn.com/cj54uKKhhL5s/?ref=app

31st Jul 2020, 5:26 AM
Bilgehan Evren
Bilgehan Evren - avatar
1 Antwort
0
The 0 means false That is if (false) 1 means true That is if (true) The if will execute only the expression returns true ,and go to the else part if it is false. #include <iostream> using namespace std; int main() { if(false) cout<<1; else cout<<2; return 0; }
3rd Aug 2020, 3:46 PM
sid
sid - avatar