int main()
{
int x=-1, y=-1;
if(++x=++y)
printf("pppppppp");
else
printf("cccccccc");
}
In C
your code won't compile [you cannot assign to rvalues
]
In C++
if(++x=++y)
invokes Undefined Behaviour.
You are assigning -1 to x and y. In the comparison, you are incrementing both variables before evaluation, so both x and y are 0. This means x=0. So x is assigned 0 and this is the result of the evaluation. Because this is regarded as false in logic operations, "ccccccccccc" is printed to the screen.
Please note that people don't usually put an assignment into an if/while/ect... and when you see this in code, it is usually an error. The comparison operator is ==.
The code tries to assign a value to something that's not a lvalue.
Pass the code eaxample to a compiler before posting.
精彩评论