Introduction
Postfix ++ and the prefix++ operators are the incrementing operators. They are used to increment the value of a variable by 1. Following is the main difference between them:-
- prefix ++: It increments the value of the variable as soon as it is encountered. It increments the variable's value before running the current line of code.
-
postfix ++: It increments the variable’s value after running the current line of code.
Now, let us see how these operators behave in the case of pointers. Pointers are basically the objects which contains the memory address.
- ++ *ptr → ++(*ptr)
- *ptr++ → *(ptr++)
There is a difference in both operators. Hence, we need to be careful in the case of pointers.
Also See, Sum of Digits in C, C Static Function
Precedence
The postfix ++ or -- has a higher priority than the prefix ++ or -- and the deference operator ‘*’. The prefix ++ or -- has a higher priority than the deference operator ‘*’.