Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C++
#include<stdio.h>
main()
{
int i=2;
printf("%d %d %d %d %d"i,i++,++i,i--,--i);
}
please explain output
Posted
Updated 29-Aug-13 23:48pm
v2
Comments
[no name] 30-Aug-13 5:50am    
Why don't you run it and find out for yourself?
Nelek 30-Aug-13 5:59am    
The easiest way is to compile and to run it, don't you think?
sairamchopparapu 30-Aug-13 6:02am    
i got answer but i don't know its explanation....
Nelek 30-Aug-13 6:15am    
Take a look to the links below
Richard MacCutchan 30-Aug-13 6:31am    
Whatever you do it will probably be wrong. It is extremely bad practice to use code like that.

actually compiler go from right to left so right most expression is --i; it means it first change value of i from 2 to 1 and print 1 then i-- it means first print value of i i.e. 1 and then decrease the value of i to 0 then ++i first increases the value of i to 1 then print 1 and next one is i++ it first print value of i i.e. 1 and the increase the value and at last value of i is 2 so it print it 2 and print order is left to right so it prints 2 1 1 1 1.
 
Share this answer
 
v2
Comments
sairamchopparapu 30-Aug-13 6:40am    
but in fedora os out put shows 2 1 2 1 2......how is it possible
[no name] 30-Aug-13 6:48am    
its depend on compiler to compiler i am describing the output of turbo c on win32. in c compiler output depends on platform and compiler so that's why u getting different output.
sairamchopparapu 30-Aug-13 6:52am    
ok so thanks for explanation..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900