Prefix vs Postfix | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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.

13th Oct 2020, 5:30 PM
Noah
Noah - avatar
2 Réponses
+ 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!!
13th Oct 2020, 5:45 PM
Matias
Matias - avatar
+ 2
Postfix decrement X-- will subtract one Prefix decrement --X.
13th Oct 2020, 5:48 PM
Matias
Matias - avatar