What's the difference between (a++) and (++a)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the difference between (a++) and (++a)?

Unfortunately I didn't understand the difference between (a++) and (++a) while I was learning the java course..help me please.

28th Aug 2017, 12:24 AM
Walid Kh. Sharaiyra
2 Answers
+ 3
a++ or a-- is postfix operation, meaning that the value of a will get changed after the evaluation of expression. ++a or --a is prefix operation, meaning that the value of a will get changed before the evaluation of expression. lets assume this; a = 4; b = a++; // first b will be 4, and after this a will be 5 // now a value is 5 c = ++a; // first a will be 6, then 6 will be assigned to c *From Denim Datta
28th Aug 2017, 12:39 AM
Sébastien Auriault
Sébastien Auriault - avatar
28th Aug 2017, 1:35 AM
Hatsy Rei
Hatsy Rei - avatar