include <stdio.h> int main() { int b=7,a; a=b++ + ++b+b++ ; printf ("%d\n",a); return 0; } | Sololearn: Learn to code for FREE!

+2

include <stdio.h> int main() { int b=7,a; a=b++ + ++b+b++ ; printf ("%d\n",a); return 0; }

Explanation please

10/22/2021 5:19:33 AM

Palleni Sasidhar

6 Answers

New Answer

+4

The statement a=b++ + ++b + b++ ; is garbage code that will produce unpredictable results. Using multiple pre/post increment/decrement operators on the same variable in the same statement will create sequence point errors. It is undefined behaviour. Just don't do it.

+2

#include <stdio.h> int main() { int b = 7, a; a = b++; printf("%d\n",a); a += ++b; printf("%d\n",a); a += b++; printf("%d\n", a); return 0; }

+2

a=b++ + ++b+b++; 1)a=((b++)+(++b))+(b++); 2)++b = 8 3)b++ = 8 4)b++ = 9 5)a=8+8+9 6)a=25 b=10

+1

I am unable to explain via chat therefore i have shared code explaination, if you know use of ++b or b++ then you will understand it. if you dont know about it then do some research

+1

Please always tag the language you're asking about. https://code.sololearn.com/W3uiji9X28C1/?ref=app

0

It produces garbage value at the result due to the variable A value is not defined. Just check this link for your understanding about the unary operators in c. https://www.quora.com/What-is-a-a-b-b-if-a-is-4-and-b-is-5/answer/Raghul-A-25?ch=10&oid=300627272&share=8d139834&srid=hqEi0&target_type=answer