+ 4
To increment or decrement the value of a variable while executing loops,why do we use the postfix operator....why not prefix??
6 ответов
+ 2
it doesn't matter in most cases and postfix version is older
+ 2
okay...thanks
+ 1
I use prefix unless there a reason not to. Normally, the compiler will optimize both to the same performance, but logically postfix uses more steps. Compare how a naive C++ compiler could implement it:
int naivePrefix(int& x) {
x = x + 1;
return x;
}
int naivePostfix(int& x) {
int y = x;
x = x + 1;
return y;
}
[edit] fixed. post and pre were swapped.
+ 1
we can use both. its depend on coder how he/she want to use
0
any of them can be used
- 1
Better use prefix as it runs before compilation..