0

I have a code like

int a=10;
a=(++a)+(a++)+(a++)+(a--)+(--a);
printf("%d",a);

this gives the output as 51.

while

printf("%d",(++a)+(a++)+(a++)+(a--)+(--a));

gives 56 as ouput.

can you please explain the flow in both the statements.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by JuhaW
0

I have a code like

int a=10;
a=(++a)+(a++)+(a++)+(a--)+(--a);
printf("%d",a);

this gives the output as 51.

while

printf("%d",(++a)+(a++)+(a++)+(a--)+(--a));

gives 56 as ouput.

can you please explain the flow in both the statements.

It doesn't matter how or whether you cook it or broil it. That is undefined behavior, and the only guarantee you'll have is that anything can happen.
Read

Edited by Aia: n/a

0

It's bad behavier to use many incrementation or decrementation with same variable in same statement. C standard does not support this.

Result depends on compiler, version and optimations on compiler. Order of incrementations could happpen in any order.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.