+ 4

What's the difference between a++ and ++a

13th Apr 2017, 7:13 PM
M.Mirajus Salehin
M.Mirajus Salehin - avatar
7 Answers
+ 10
a++ called post increment of "a" returns "a" and then increments "a". b = a++ means b = a and a = a + 1 ++a called pre increment of "a" increments "a" and then returns "a". b = ++a means a = a + 1 and b = a
13th Apr 2017, 7:16 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 5
this question has been answered upwards of 10 times
13th Apr 2017, 7:36 PM
Edward
+ 4
Here's an answer to your question: Sugession: please search the forum before posting a question. Thanks https://www.sololearn.com/discuss/305422/?ref=app
13th Apr 2017, 7:26 PM
Shraddha
Shraddha - avatar
+ 1
a++; Means post incrementing a value. ++a; means pre incrementing a value. Example: int a=5; int b= a++; post increment, it means b=a=5 and than a will be increased by 1. int c= ++b; pre increment, it means b will be increased by 1 first than its value will be passed to c so c=b=6. cout<<a<<"\n"<<b<<"\n"<<c; Prints 6 6 6
13th Apr 2017, 7:28 PM
Deepak Gupta
0
No, it's not undone. The value of 'a' will be 13.
14th Apr 2017, 4:48 AM
Zaur Kandokhov
Zaur Kandokhov - avatar
- 1
'a++' copies 'a', increments it and returns the non-incremented copy. '++a' increments it and returns the incremented 'a'.
14th Apr 2017, 1:22 AM
Denis Felipe
Denis Felipe - avatar
- 3
it is fine, but the mess is when the operators are called in condition checking. For example: a=10; if(++a==10){ a=0;} else{ a+=2; } //what will be the value of a now? as I think when the condition evaluates to false the operation made on the variable is undone. if I am correct
13th Apr 2017, 7:26 PM
WONDE-TOM
WONDE-TOM - avatar