- 1
B++is b=b+1 then I want to understand ++b what is it??
2 Réponses
+ 4
b++ and ++b are equivalent if used alone. The difference is when you use them in an expression.
++b increments b, then is evaluated (pre-increment)
b++ is evaluated, then increments b (post-increment)
Example:
int a, b;
b = 1;
a = ++b; //a = 2, b = 2
b = 1;
a = b++; //a = 1, b = 2
+ 1
it's the same, b=b+1
But x=y+(b++) you use b and then increment it:
x=y+b then b=b+1
x=y+(++b) you first increment b, and then you use it:
b=b+1 then x=y+b