+ 3

If elsw

int i=20; if(i=10) // without == it is running successfully Cout <<i; The output comes out to be 10 but How i=10 becomes true

14th Jul 2018, 2:57 PM
Siddharth Jain
Siddharth Jain - avatar
2 Answers
+ 8
Also, after assign, expression return assigned value (10). Then it will be converted from int to bool: bool(10) == true
14th Jul 2018, 3:05 PM
Rull Deef đŸș
Rull Deef đŸș - avatar
+ 1
you are using the assignment operator =, you need to use the equality operator ==. if (i==10) cout<<i; the difference i=10; i equals 10 assigns 10 to i; i==10; i is equal to ten sees if the variable i is equal to the number 10
14th Jul 2018, 3:00 PM
StealthyTaco
StealthyTaco - avatar