0

What is different between i++ and ++i?

For example: Cout <<i++; Cout << ++i; What is different between 2 statement above?

13th Sep 2021, 6:31 PM
Z.sl
Z.sl - avatar
3 Answers
+ 3
++i first increment then use pre increment means in Expression first this will be solve means value will be increase by one i++ means value then increment this is known as post increment cout<<++i ; here initial value is 0 suppose so it will print 1 If u print this cout<<i++ it will print 0 then in next line it will increase
13th Sep 2021, 6:46 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
I++ is called post increment operator and ++I is called pre increment operator, both of the operator increase the value of I by 1, but post increment first perform the operation (like you're printing I) and then increment the value of I, and pre increment is opposite. in case you if you want to know more about that: https://www.geeksforgeeks.org/what-is-the-difference-between-i-and-i-in-java/
13th Sep 2021, 6:44 PM
Rupali Haldiya
Rupali Haldiya - avatar