#include <stdio.h>
int main()
    int i=5;
    printf("%d %d %d %d %d", --i,i--,++i,--i,i);

    return 0;

Edited 3 Years Ago by Reverend Jim: Fixed formatting

it is easy
i is 5
then -- i which means (i) is 4
then i-- which will appear 4 then i will be 3 then
++i which means increase by one so (i) is 4 then
-- i becomes i is 3, then print last (i) which is 3

the result is 4 4 4 3 3
please reply if I am mistaken

> please reply if I am mistaken
You are mistaken.
Read the link Aia posted.

Trying to rationalise what you expect to happen, or merely posting what your current compiler gives you is no way to go.

Thank you I learnt somthing from you
but I was thinking the program will run as
this following:

int main()
int i=5;

return 0;

That would be a completely different program, which is fine.

Use that FAQ to also look up "sequence points". You'll see that each side effect is separated by a sequence point, so there is no issue about the order of things and your program is well defined.

But to say it always has the same output as the one-liner in the original post would be wrong.

Did you run the program before asking?

Running a given program is not a garantee that is correct, legal code.

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