void main()
{
int a = 5 , b =6, c=0;
c = a++ + b++ + ++b + ++ a + a++;
printf("c = %d \n", c);
getch(); 
}

the result of the code is

c = 32

while if we write the following code the result is 33

void main()
{
int a = 5 , b =6;
printf("%d \n", a++ + b++ + ++b + ++ a + a++);
getch(); 
}

Edited 6 Years Ago by WaltP: Fixed CODE tags -- use the PREVIEW button

if u remove the space ++ a to ++a then also the result will not be the same

These lines of code violate the C standard, and are ridiculous to boot.

If you dared to write a line of code like that on a job, you'd be in trouble, for sure.

You can't stop this kind of question (and this thread), fast enough.

adak i am not doing so in development of a software ..
these type of questions were there in google's interview

adak i am not doing so in development of a software ..
these type of questions were there in google's interview

The right answer is. This invoke undefined behavior.
If you need a why, you need to learn about sequence points.

Edited 6 Years Ago by Aia: n/a

This article has been dead for over six months. Start a new discussion instead.