A++ and --A | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

A++ and --A

if A++ is like A = A + 1 then whats --A?

16th Jan 2017, 10:10 AM
Erik Go
Erik Go - avatar
2 Answers
+ 1
--a is pre decrement. It will decrease value of a by 1.
16th Jan 2017, 10:21 AM
Divesh Agarwal
Divesh Agarwal - avatar
+ 1
You have to differentiate between post and pre increment. These 2 have different meanings. For Pre : ++a // means a=a+1 --a // means a=a-1 For post : a++ // a=a+1 a-- // a=a-1 The difference between pre and post is the order of execution. Pre first de/increases its value then continues the normal order. post first calculates its current calculation with the current value. Then de/increases the variable by one. Then continues with the normal order.
16th Jan 2017, 10:33 AM
Andreas K
Andreas K - avatar