+ 1

What is the difference between ++x and x++ in java? Please give the output of both also if x=6.

Question says it all.

19th Feb 2017, 12:43 PM
Meharban Singh
Meharban Singh - avatar
3 ответов
+ 5
1. ++x indicates a prefixed increment. Here the. incremented value of x will be available. x=6; y=++x; /* implemented as x = x + 1; y = x; */ System.out.println (x); // outputs 7 System.out.println (y); // outputs 7 2. x++ indicates a postfix increment. Here value of x will be used before increment. x=6; y=x++; /* implemented as y = x; x = x + 1; */ System.out.println (x); // outputs 7 System.out.println (y); // outputs 6 Hope this helps
19th Feb 2017, 1:01 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
thanks @devender mahajan
18th Jun 2017, 4:47 AM
kartik B
kartik B - avatar
0
Thanks @DevenderMahajan
23rd Feb 2017, 9:41 AM
Meharban Singh
Meharban Singh - avatar