+ 3
Difference between ++a and a++
5 ответов
+ 3
This is what called Operator precedence.
Operator precedence determines the order in which operators are evaluated. Operators with higher precedence are evaluated first.
A common example:
3 + 4 * 5 // returns 23
The multiplication operator ("*") has higher precedence than the addition operator ("+") and thus will be evaluated first.
Complete description of operator precedence in Javascript is here:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
+ 2
int a = 2
int b = ++a -> b = 3 and a = 3
int b = a++ -> b = 2 and a = 3
+ 1
I'm assuming C# took this from C, so here goes:
++a is pre-increment, and a++ is post-increment. The difference lies in which value is used in the rest of the expression containing it. With ++a, a is incremented first, and that is the value you get; with a++ you get the value of a, and a is incremented afterwards. N3tW0rK's answer illustrates it perfectly.
If, on the other hand, your only aim is incrementing a and the value isn't being used, there is effectively no difference between them, and which one you use is largely a matter of personal taste.
+ 1
what the difference between a++ and ++a
++a : it means increments then asign the value
ex:
int a=3;
int y=++a;
now y = 4 and also a=4
a++ : it means asign then increment the value
ex:
int a=3;
int y=a++;
now y=3 and a=4
0
GGG