+ 1

What is the difference between (i++) and(++i)??

25th Aug 2017, 5:19 AM
Narjess
4 Answers
+ 1
i++ and ++i are unary operators which perform increment operation. Let us say, i = 0, i++ => i = i + 1; That is the incrementation takes affect only after the current statement but ++i => i = 1 + i; Here the incrementation takes affect during the execution of that particular statement itself.
25th Aug 2017, 5:30 AM
Yesha Krish
Yesha Krish - avatar
+ 12
int i=1; case 1: cout<<i++; // outputs 1 because postfix I.e., value will be incremented after case 2: cout<<++i; // outputs 2 prefix I.e, incremented before
25th Aug 2017, 5:36 AM
P R
P R - avatar
+ 8
i++ is postfix ++i is prefix
25th Aug 2017, 5:29 AM
Amethyst Animion
Amethyst Animion - avatar
25th Aug 2017, 5:36 AM
Hatsy Rei
Hatsy Rei - avatar