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.

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

thanks

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.