Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
These unary operators increase or decrease a value by 1. The key difference is when the change happens — before or after using the value.
++xPre-incrementIncrements THEN returns value
x=5; y=++x; // x=6, y=6x++Post-incrementReturns value THEN increments
x=5; y=x++; // x=6, y=5--xPre-decrementDecrements THEN returns value
x=5; y=--x; // x=4, y=4x--Post-decrementReturns value THEN decrements
x=5; y=x--; // x=4, y=5In loops, ++i is preferred over i++ for iterators as it avoids creating a temporary copy. For primitive types, modern compilers optimize both equally.