4
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by deceptikon
-1

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

1

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.

Edited by deceptikon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.