void main()
{
int i=2;
clrscr();
printf("%d  %d  %d %d %d",i++,i--,--i,++i,i) ;
getch();
}

line 5 is undefined behavor, the value printed for i may be difference from one compiler to the next.

With reference to ur program,
Nice to meet you...
Actually the printf() statement will work according to the stack mechanism i.e., the evaluation (execution) will starts from right side to left side...

printf("%d %d %d %d %d",i++,i--,--i,++i,i) ;
value of i is 2
follow the procedure right to left
first it will print 2
++i is a pre-incrementation so the value of i is increased by 1
--i is a pre-decrementation so the value of i is decreased by 1
i-- is a post-decrementation after passing the value it will decrement
i++ is a post-incrementation after passing the value it will increment

and the output of this program is
1 2 2 3 2

Actually the printf() statement will work according to the stack mechanism i.e., the evaluation (execution) will starts from right side to left side...

Yet the compiler is free to actually evaluate the arguments in any order at all. Just because the values might be pushed from right to left doesn't mean the expressions used to produce a value will be evaluated in the same order.

Modifying a variable multiple times between sequence points is undefined behavior. All predictability is gone, even between runs of the program from the same compiler.

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.