Difference Between i++ and ++i

What is the main Difference Between i++ and ++i? when should I use ++i? Can you please elaborate…Thank you

i++ is post increment and ++i is pre increment in post increment it returns the value first and then increment itself by 1 after returning but in pre increment it 1st increments it’s value by 1 and then return the value after increment. Use ++I if u want to return the incremented value

2 Likes

i++ and ++i are both increment operators. The difference is that i++ assigns the value and than returns the value after it is incremented whereas ++i increments the value first and than assigns it.