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;
}
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;
}
Copyright © 2021 Jogjafile Inc.
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