When increment operator is used independently, prefix and postfix form work similarly. For example, the result of A++ and ++A is same.
But when increment operator is used in a larger expression with other operators, prefix and postfix forms work differently. For example, the results of two statements A = ++B and A = B++ are different.
In prefix form, The statement A = ++B contains two operators ++ and =. It works in following order:
- It increments the value of B by 1.
- It assigns the value of B to A.
In postfix form, the statement A = B++ works in the following order :
- It assigns the value of B to A.
- It increments the value of B by 1.
No comments:
Post a Comment