When we use i++ and ++i in our code we think both of the statements are alternative. But there is a big difference between them. I try to show the difference between i++ and ++i shortly below. Before that, we first look at a code below and try to understand;
Output for this code;
if we look at the output for this code we got sure that there is no difference between i++ and ++i. For this code both of the statements work same because of the primary work of i++ and ++i is increasing the index number. But that works happened in different ways.
i++ refers to post-increment.
++i refers to pre-increment.
Now try to understand carefully in cases of i++, it increments the value of i but returns the original value before incrementing. And it stores the value on its own.Now see a code;
And the cases of ++i, it increments the value of i and it also returns the incremental value.
let’s see the code;