int main()
{
int x=-1, y=-1;
if(++x=++y)
printf("pppppppp");
else
printf("cccccccc");
}
views:
41answers:
3
+2
A:
In C
your code won't compile [you cannot assign to rvalues
]
In C++
if(++x=++y)
invokes Undefined Behaviour.
Prasoon Saurav
2010-09-29 10:53:11
thiscodegivesoutput pppppppp
2010-09-29 10:54:37
but wecant assign constant to a constant so it shouldgiveerror
2010-09-29 10:55:07
2010-09-29 10:56:24
@User : Are you compiling your code as a `*.cpp` file? In C assignment to `++x` is not valid.
Prasoon Saurav
2010-09-29 10:56:57
C++ was not tagged, so you can omit C++. The code just dont pass the C compiler.
harper
2010-09-29 10:58:47
A:
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 ==.
Alexander Rafferty
2010-09-29 10:55:35
A:
The code tries to assign a value to something that's not a lvalue.
Pass the code eaxample to a compiler before posting.
harper
2010-09-29 10:57:37