Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Inc

Name: Anonymous 2012-02-02 17:45

I have a question regarding ++
i=0;
printf("%d %d %d,i++,i++,i++);
 will return
2 1 0
why?

Name: Anonymous 2012-02-02 17:47

>>1
It's an undefined behavior. The arguments may be evaluated in whatever order.

Name: Anonymous 2012-02-02 17:51

Well it prints in descending order so there must be some order to it

Name: Anonymous 2012-02-02 17:51

Change the order of the "i++"'s and you'll get 0 1 2.

Name: Anonymous 2012-02-02 17:57

Not this again...

>>3
Of course it happens in some order, but it's undefined in which it will. On another compiler/machine the answer might be different.

>>4
Lol. Same time. IHBT!

Name: Anonymous 2012-02-02 18:11

What happens when you want to do something like
 printf("%d %d",a[i++],a[i++]); ?

Name: Anonymous 2012-02-02 18:12

>>6
Like it has been said a hundred times already, undefined behavious. Motherfucker.

Name: Anonymous 2012-02-02 18:13

>>6
Then you do something like it. Something with defined behaviour. But you don't do that.

Name: Anonymous 2012-02-02 18:42

>>6
printf("%d %d",a[i],a[i]);
i += 2;

Don't change these.
Name: Email:
Entire Thread Thread List