|
Hi developers,
I am interested to so solve this chunk of code
void main()
{
int Var = 90;
if(Var += Var == ++Var == 89)
printf(" %d ",Var);
}
After executing the code i m getting the answer "91"
I am really surprised with the answer. Infact, I am not clear with operator precedence in this problem. Please give some help for it.
Thanks.
Amrit Agrawal, Mumbai
|
|
|
|
|
The rules are that expressions such as this may lead to incorrect results. You need to split it into constituent parts.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Amrit Agr wrote: Please give some help for it.
Rewrite it so it is more maintainable.
|
|
|
|
|
void main()
{
int Var = 90;
if(Var += (((Var == (++Var)) == 89)))
printf(" %d ",Var);
}
Operator precedence:
1. Increment operator (++)
2. Relational operator (==), and its Associativity is Left to Right
3. Assignment operator (+=)
Hope it helps...
|
|
|
|