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(); 
}

Recommended Answers

All 9 Replies

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

please someone answer my query

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.

This is why you can't do what you posted.

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.