0
can any one explain about prefix and postfix operators completely with an example ?
3 Antworten
+ 12
@Gordie | Oh, I actually didn't know that. Thanks, sorry!
+ 11
People ask this a lot...there's a similar question like 10 posts down. I'll explain anyway.
Prefix (++x, --x) has high priority/precedence, and adds/removes 1 from the variable first and foremost. Other math and operations are done next.
Ex: y = ++x; //Adds 1 to x, then assigns x to y.
Postfix (x++, x--) has low priority. After all other operations are done, 1 is added/removed from the variable.
Ex: y = x++; //Assigns the old value of x to y, then adds 1.