hi
what is the difference between a++ and ++a
a++ is known as post-increment and ++a is kown as pre-increment.
i++
is post increment because it increments i
's value by 1 after the operation is over.
Example:
int i = 1, j;
j = i++;`
Here value of
`j = 1` but `i = 2`
Here value of i
will be assigned to j
first then i
will be incremented.
In the case of ++a
++i
is pre increment because it increments i
's value by 1 before the operation. It means j = i;
will execute after i++
.
Example:
int i = 1, j;
j = ++i;
Here value of j = 2
but i = 2
. Here value of i
will be assigned to j
after the i
incremention of i
. Similarly ++i
will be executed before j=i;
.
I hope this is helpful @Amoako