0
Prefix vs Postfix
I am learning C# and am still a beginner. I came across the C# lesson about "Assignment & Increment Operators" and was confused. Can someone explain the difference between prefix and postfix increments? Thank you. P.S. Also how they work. Thank you.
3 ответов
+ 2
Prefix Operator
The increment operator ++ if used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the prefix decrement operator works but it decrements by 1.
For example, an example of prefix operator −
++a;
Postfix Operator
The increment operator ++ if used as postfix on a variable, the value of variable is first returned and then gets incremented by 1. It is called Postfix increment operator. In the same way the decrement operator works but it decrements by 1.
An example of Postfix operator.
a++;
Thank you!!
+ 2
Postfix decrement X-- will subtract one
Prefix decrement --X.