0
X++, ++x, x+ etc
I really don't understand a thing
3 ответов
+ 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.
+ 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;
}
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