Why is there a difference in output?
class Amie
{
public static void main(String...a)
{
int i=5;
i=++i/i++;
SOP(i);
}
}
OUTPUT=1
in C ---
void main()
{
int i=5;
i=++i/i++;
printf(i);
}
OUTPUT = 2
Why is there a difference in output?
class Amie
{
public static void main(String...a)
{
int i=5;
i=++i/i++;
SOP(i);
}
}
OUTPUT=1
in C ---
void main()
{
int i=5;
i=++i/i++;
printf(i);
}
OUTPUT = 2
Java standard does reglament how such an expression should be evaluated and there is only 1 possible answer - 1.
In case of C there is no guarantee from standard for possible optimization. You could receive 2 as well as 1 in executables generated by other compilers. So it is undefined behaviour in C