The postfix decrement operator x in C language--first returns the unmodified x value and then decrements it, while the prefix decrement operator--x first decrements the x value before assigning it to x .
x-- and --x in C language
In C language, x-- and- -x are both decrement operators, used to reduce the variable x by 1. The difference between them is the order of operator execution.
x-- (Suffix Decrement)
--x (prefix decrement)
Difference
So the main difference is that postfix decrement first returns the unmodified x value and then decrements it, whereas prefix decrement first decrements the x value, Then assign it to x.
Example
The following example shows the difference between x-- and --x:
int x = 5; int y = x--; // y = 5, x = 4 int z = --x; // z = 3, x = 3
Conclusion
The above is the detailed content of The difference between x-- and --x in c language. For more information, please follow other related articles on the PHP Chinese website!