+ 1

Please help, explain me how output is 3 .. not 4?

int main() { int a=0; a=a++ + a++ - a++ + ++a; printf("%d",a); return 0; }

30th Sep 2020, 12:38 PM
C Lover
3 Réponses
+ 2
Your program sequence point issue so It is undefined by standards. You may get different answer in different compilers... Read the warnings, it may evaluated from right to left or left to right.. So you get different values... a = a++ + a++ - a++ + ++a; Edit : @c Lover https://www.sololearn.com/Discuss/2223222/?ref=app
30th Sep 2020, 1:00 PM
Jayakrishna 🇮🇳
0
According to BODMAS addition will be done first after that only subraction right?
30th Sep 2020, 12:44 PM
C Lover
0
C Lover The result of that expression is undefined in the standard since you're trying to read from and modify the same variable between two consecutive sequence points.(Or in the same expression) Just as Jayakrishna🇮🇳 has said,the result might vary from compiler to compiler
30th Sep 2020, 2:15 PM
Anthony Maina
Anthony Maina - avatar