Is that for 1 return to True value and 0 return to False value? The output is 111
#include <iostream>
using namespace std;
int main()
{
int x = 8, y = 10;
if (x = 2 && y > x)
cout << y + 1;
cout << x;
}
Is that for 1 return to True value and 0 return to False value? The output is 111
#include <iostream>
using namespace std;
int main()
{
int x = 8, y = 10;
if (x = 2 && y > x)
cout << y + 1;
cout << x;
}
As the &&
operator has a higher operator precedence than the =
operator, the condition of the =
operator is being treated as assigning a boolean value to x
as-if you had written:
x = (2 && (y > x))
Not as:
(x = 2) && (y > x)
For better experiences, use parenthesis explicitly:
if ((x = 2) && (y > x))