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

variable++ vs ++variable

PREFIX OR SUFFIX? That is a question.

30th Sep 2016, 7:03 AM
Piotr
Piotr - avatar
3 Answers
+ 11
prefix changes value prior usage, suffix after Example: int x = 5; cout << ++x; // x becomes 6, prints 6, cout << x++; // prints 6, x becomes 7 cout << x; // prints 7
30th Sep 2016, 7:11 AM
Max Adams
Max Adams - avatar
+ 3
PREFIX increments the variable before getting her state. SUFFIX getting state of the variable before increment her. I am sorry i am not very speek english.
30th Sep 2016, 7:09 AM
Piotr
Piotr - avatar
+ 2
Fu.k, today i had an short examine of this and 70% of class get 1 (me 3), becouse our teacher thinks we can everything :P Ps. Siemano piotrek
3rd Oct 2016, 8:08 PM
ArekadiuszBy
ArekadiuszBy - avatar