What is difference between pre increment and post increment operator overloading? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is difference between pre increment and post increment operator overloading?

only have minor different

8th Apr 2017, 5:42 PM
Harish kumawat
Harish kumawat - avatar
3 Answers
+ 7
Simply put, ++x increments value and then uses the variable. x++ uses the variable and then increments
8th Apr 2017, 5:51 PM
Pixie
Pixie - avatar
+ 7
You already mentioned the difference in your question (Post and Pre increment). int x = 5; cout<< x++; // 5 cout<< x; // 6 cout<< ++x; //7 (x is instantly incremented)
8th Apr 2017, 5:56 PM
Wisdom Abioye
Wisdom Abioye - avatar
+ 2
Operator overloading is overloading an operator to perform the same operation on different things of objects. Pre increment operator overloading will first increment the quantity or value and then assign it to the variable. On the contrary, post increment operator overloading will assign the value or quantity to the variable and then increment it. For example, int x=2; cout << ++x; //prints 3 to the console ( first increments) int x=2; cout << x++; // prints 2 to the console ( first it is assigned or the specific operation is performed and then incremented ) cout << x; //prints 3 to the console ( form line 2 clearly x has been incremented. So, 2+1 = 3)
8th Apr 2017, 5:49 PM
Vishnu ks
Vishnu ks - avatar