I had an interview last week and the interviewer asked me this operator precedence issue. Please somebody help me in understanding the logic for this program. I am working on Ubuntu(linux)
int main()
{
int var = 90;
if(var += var == ++var ==8)
printf("val of var is %d \n",var);
}
The output of this program is 91.
How is multiple == in the loop evaluated (associativity is left to right)???
Interestingly if I tweak the code as
int main()
{
int var = 90;
if(var += var == ++var)
printf("val of var is %d \n",var);
}
Then the output comes as 92.
Is this behavior a compiler dependent thing???