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

1 Like