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

++a and a++

what actually is ++a and a++..I didnt get it

18th Mar 2017, 6:12 PM
ank
ank - avatar
5 Answers
+ 7
a++ and ++a adds 1 to a. a++ is post-incrementation, meaning that a will be incremented(add 1 to a) AFTER this line of code(hence called post). ++a is pre incrementation,meaning that a will be incremented AT this line. Example:- y=a++;//here value of y will be same as that of a(y will NOT be equal to a+1), but a will be incremented.(Hence post). y=++a;//here value of y will be that of a+1, and a will be incremented also.(Hence pre)
18th Mar 2017, 6:57 PM
Meharban Singh
Meharban Singh - avatar
+ 2
holy hell thank you for this Meharan Singh! Seems like something I should have known but this has been giving me trouble all morning.
18th Mar 2017, 7:15 PM
Robert works
Robert works - avatar
+ 2
thanks guys bt Its really confusing during codes..specially during for loop
19th Mar 2017, 2:05 AM
ank
ank - avatar
+ 2
int a = 5; cout<<a++<<endl; cout<<a; ---------------- 5 6 |||||||||||||||||||||||||||||||||||||||||| int a = 5; cout<<++a<<endl; cout<<a; ----------------- 6 6
20th Mar 2017, 9:56 AM
Tofiq
Tofiq - avatar
+ 1
Welcome guys :-)
19th Mar 2017, 4:55 AM
Meharban Singh
Meharban Singh - avatar