This is a question from kn king\'s c programming : a modern approach. I can\'t understand the solution given by him:-
The expression ++i is equivalent to (i
++i
is the pre-increment operator. It increments i
before setting and returning the value (which is obviously i + 1
).
Now, i++
is the post-increment operator. It increments i
after the whole instruction it appears in is evaluated.
Example:
int i = 0;
std::cout << ++i << std::endl; /* you get 1 here */
std::cout << i++ << std::endl; /* you still get 1 here */
std::cout << i << std::endl; /* you get 2 here */