X++, ++x, x+ etc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

X++, ++x, x+ etc

I really don't understand a thing

29th Nov 2016, 3:00 PM
Anowo
Anowo - avatar
3 Answers
+ 5
Like what QZUIO stated, both adds a numerical value by 1. And they both have a significant difference : postfix and prefix form. ++x; is prefix and x++; is postfix If you do : int x=0; cout<<x++<<endl; The system will write the number '0' on the console. However, this : int x = 0; cout<<++x<<endl; this code will make the system write the number '1' on the console. This means that prefix adds the value first before processing the code. But postfix processes the code first before adding the value.
29th Nov 2016, 3:47 PM
Wen Qin
Wen Qin - avatar
+ 1
X++ and ++X is the same thing as x+1 or 1+x. You can try this out and you will see the difference between each other: #include<iostream> using namespace std; int main(){ int x=0; int y=0; cout<<x++<<endl; cout<<++y<<endl; return 0; }
29th Nov 2016, 3:11 PM
QZUIO
QZUIO - avatar
0
The prefix decrement increases the value of its operand before it has been evaluated. ... Prefixincrement/decrement change the value before the expression is evaluated. Postfixincrement/decrement change the value after.11
29th Nov 2016, 3:56 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar