by ballard · 13y ago · 0 comments
/* x++ */
inline int postincrement(int *x) {
int temp = *x;
*x = *x + 1;
return temp;
}
/* ++x */
inline int preincrement(int *x) {
*x = *x + 1;
return *x;
}
But in typical usage, where the expression value is not used, it doesn't make any difference: for (int i = 0; i < 10; ++i) {
If one looks at the assembly, it's clearly equivalent to: for (int i = 0; i < 10; i++) {
Incidently, the latter seems more readable.Compilers are sometimes smart enough to remove the unnecessary operation in C++ (e.g. switch to ++x themselves), but I always use ++i for the same reason people simplify their usage of C in between sequence points --- it's an easy transformation, and why tempt fate?
To her credit, she didn't penalize me for disagreeing with her and I still got the offer.