Code:`when x=5;`

System.out.println(x++ + ++x);

output->12

why it print 12

anyone can tell me please....

Printable View

- 10-18-2010, 05:11 PMrohitjavaplease help in java funda...Code:
`when x=5;`

System.out.println(x++ + ++x);

output->12

why it print 12

anyone can tell me please.... - 10-18-2010, 05:15 PMeRaaaa
what did you expect and why?

EDIT: look in here too - 10-18-2010, 05:20 PMrohitjava
- 10-18-2010, 06:06 PMTolls
x++ evaluates to 5, which is then added to ++x which will evaluate to 7.

- 10-18-2010, 07:13 PMgauravfzd
when x++ is encountered the value of x was 5, after x++ it becomes 6 then after encountering ++x the value of x becomes 6+1=7 which is then added to the previous value of x i.e. 5 to produce 12