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
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)
+ 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.
+ 2
thanks guys bt Its really confusing during codes..specially during for loop
+ 2
int a = 5;
cout<<a++<<endl;
cout<<a;
----------------
5
6
||||||||||||||||||||||||||||||||||||||||||
int a = 5;
cout<<++a<<endl;
cout<<a;
-----------------
6
6
+ 1
Welcome guys :-)