+ 1
[DUPLICATE] What is difference between i++ and ++i
9 Answers
+ 5
post increment = x++
pre increment = ++x
int x = 5;
int y = x++;
Now x is 6 and y is 5.
int x = 5;
int y = ++x;
Now both x and y are 6.
The pre-increment first do increase/decrease of the variable and next some operetions.
The post-increment do some operations first and at the end increase variable.
+ 5
a = i++ means variable a is set to the value of i, then value of i is added by 1, so a!=i
a = ++i means value of i is added by 1, then a is set to value of i, so a==i
+ 3
When using post-increment (i++), the expression is evaluated first and then the value of the variable "i" gets incremented by 1.
In case of pre-increment (++i), the value of variable "i" is first raised by 1, and then the given expression is evaluated.
edit: Saran hope this helps.
https://code.sololearn.com/cGm5AK5vHiUz/?ref=app
+ 3
i++ is called post increment.... Current value of i is used to evaluate the statement and then increment value of i by 1.
++i is pre increment... Here value of i incremented by 1 and incremented value is used in the given statement.
Int i = 5;
Print i++
5
Print ++i
6
+ 2
Nice Deepak....
+ 1
give an example program
+ 1
Tks bro
0
Saran it's my pleasure.