+ 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 RĂ©ponses
+ 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