+ 4
What's the difference between a++ and ++a
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
+ 5
this question has been answered upwards of 10 times
+ 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
+ 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
0
No, it's not undone. The value of 'a' will be 13.
- 1
'a++' copies 'a', increments it and returns the non-incremented copy. '++a' increments it and returns the incremented 'a'.
- 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