i think, the codesample in c given below should output: 10,15,10. But it gives output: 15,15,15. my question is how this result comes?
#include <stdio.h> int main() { int a=10; printf("%d %d %d",a,a=a+5,a); return 0; }
Then you are in the realm of undefined behaviour.
The C standard does not say in what order arguments are evaluated.
So on one compiler the right 'a' might be evaluated first, then a=a+5 and then the first will be 15.
a=a+5
Then you'll get 15, 15, 10.
Another compiler will evaluate the other way around.
Then you'll get 10, 15, 15
Then you are in the realm of undefined behaviour.
The C standard does not say in what order arguments are evaluated.
So on one compiler the right 'a' might be evaluated first, then
a=a+5and then the first will be 15.Then you'll get 15, 15, 10.
Another compiler will evaluate the other way around.
Then you'll get 10, 15, 15