#include<stdio.h>
#include<conio.h>
main()
{
int a=2,b;
b= a++ + ++a + a++;
printf("%d,%d",a,b);
getch();
}
According to me output should be 5,10. But output given in 5,9. Why?
#include<stdio.h>
#include<conio.h>
main()
{
int a=2,b;
b= a++ + ++a + a++;
printf("%d,%d",a,b);
getch();
}
According to me output should be 5,10. But output given in 5,9. Why?
Refer this thread and the links mentioned on the same. You can never be sure of the order of evaluation in such expressions which have undefined behaviour and where the value of a variable is getting modified more than once between two sequence points which is not allowed/defined as per the standards. However, compiling the code on ideone gives 5,10 as the output, this may differ on other compiler too!!