0

What is postfix and prefix?

14th Jul 2016, 1:58 PM
Jeet
Jeet - avatar
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
14th Jul 2016, 2:04 PM
deepak h.s
deepak h.s - avatar
+ 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;
14th Jul 2016, 4:15 PM
this->getName()