Engineering Full Stack Apps with Java and JavaScript
Predict output:
public class PrefixPostfixCheck { public static void main(String[] args) { int i=5; i=i++; System.out.println(i); } }
http://javajee.com/prefix-and-postfix-operators-in-java
This will print 5.
For any two variables a and b,
b = a++ expands to
temp = a;
a = a + 1;
b = temp;
Therefore, a = a++ expands to:
a = temp;
So irrespective of the increment, a is assigned its original value as stored in temp.
Hence it is adviced not to use a single variable in more than one assignment.
Refer to the reference link from javajee for all such expansion.
Logged in users see lesser ads and get more features.
If you want to solve the questions together with the experts and understand the concepts better, please contact us using the contact form or WhatsApp numbers. Selected people get to do that without any additional charges.