it is a silly Q for most of u - i know - but i one of the beginner here, and I can not understand why the output in here are 12 what does this (x--
) do to the resu
x--
subtracts/decrements the value of x by one.
Conversley x++
adds/increments by one.
The plus or minus signs can either be before (--x
) or after (x--
) the variable name, prefix and postfix. If used in a expression the prefix will return the value after operation has been performed and the postfix will return the value before operation has been performed.
int x = 0;
int y = 0;
y = ++x; // y=1, x=1
int x = 0;
int y = 0;
y = x++;// y=0, x=1