+ 1

Can anyone please explain to me what is a postfix?

I want a more briefly explained definition about postfix

3rd Apr 2017, 5:55 AM
George C Thomas
George C Thomas - avatar
2 Answers
+ 15
i = 5; System.out.println(++i); //6 This prints out "6" because it takes i adds one to it and returns the value. 5+1=6; This is prefixing, adding to the number before using it in the operation. i = 6; System.out.println(i++); //6 (i = 7, prints 6) This prints out "6" because it takes i, stores a copy, adds 1 and returns the copy. So you get the value that i was, but also increment it at the same time. Therefore you print out the old value but it gets incremented. The beautfy of a postfix increment. Then when you print out i, it shows the real value of i because it had been incremented. 7 source: stackoverflow.com
3rd Apr 2017, 5:58 AM
Dev
Dev - avatar
0
Thanks
3rd Apr 2017, 7:03 AM
George C Thomas
George C Thomas - avatar