+ 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
2 Answers
+ 8
Also, after assign, expression return assigned value (10). Then it will be converted from int to bool:
bool(10) == true
+ 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