+ 1
What is difference between pre increment and post increment operator overloading?
only have minor different
3 Respostas
+ 7
Simply put,
++x increments value and then uses the variable.
x++ uses the variable and then increments
+ 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)
+ 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)