I found that the precedence and associativity rules are different in C, C++ and Java. Have a look at this code snippet:
#include<stdio.h>
void main(){
int k = 5;
int x = ++k*k--*4;
printf("%d",x);
}
The above C program gives the output as 120
Look the following Java code:
class Main
{
public static void main(String args[])
{
int k = 5;
int x = ++k*k--*4;
System.out.println(x);
}
}
This Java code gives 144 as output. Why this difference? I think the Java evaluation strategy is correct because it is evaluated as (pre increment)6 * 6 (post decrement) *4 = 144
Then what's wrong with C and C++? C and C++ both give 120.