- 2

What is the output?

int i = 5; System.out.println(i++); System.out.println(++i);

25th Nov 2016, 1:17 PM
JĂłzsef Halasi
JĂłzsef Halasi - avatar
2 Answers
+ 1
This is Java. Why it has a c++ tag? the output is : // 5 // 7
25th Nov 2016, 1:24 PM
Alireza M
Alireza M - avatar
- 1
i++ will perform the increment AFTERWARDS, so you get 5 on that one and move along with its value changed to 6. ++i performs the increment BEFORE, so its value becomes 7 and then is printed
25th Nov 2016, 2:00 PM
Matthew Shephard
Matthew Shephard - avatar