0
What is postfix and prefix?
2 Answers
0
postfix x++ ,this means value is assigned before incrementing the variable
prefix ++x ,this means variable is incremented and then that value is assigned
"pre"fix ,variable is incremented first
"post"fix , variable is incremented after assigning value
+ 2
To add more detail to the answer of deepak, prefix is faster than the postfix.
Why?
The postfix has 4 things to do:
1: Make a copy of the variable.
2: Increment the original value.
3: Use that new copy. (Maybe this does not count?)
4: Delete the newly created copy.
While the prefix has to do only 2 things:
1: Increment the value.
2: Use it. (Same as above).
So, if you have this piece of code in your program:
...
x++; // This statement only increments the value.
...
You really should change that to ++x;