difference between --a and a-- c++
--a
The expression --a
is a pre-decrement operator in C++. It decrements the value of variable a
by 1 before using the updated value in the expression. Here is the step-by-step explanation of --a
:
- The value of
a
is decremented by 1. - The updated value of
a
is used in the expression where--a
is present.
a--
The expression a--
is a post-decrement operator in C++. It decrements the value of variable a
by 1 after using the original value in the expression. Here is the step-by-step explanation of a--
:
- The original value of
a
is used in the expression wherea--
is present. - The value of
a
is decremented by 1 after the expression is evaluated.
Let me know if you need further assistance!