|
|
= is the assignment operator not comparison which is ==.a adds 1 to it and assigns it back to a. Shorter it would be a++; or ++a; or a += 1. They all express the same.| and which a does the result look for to + b ? |
result is positive or not? No it doesn't. For this you may use abs():a = 5; means, take the value on the right hand side of the = sign and store it in the variable to the left of the =.a = a + 1; means first calculate the result of whatever is on the right, a + 1 then after doing that, store the result in the variable on the left. | a | b | result |
----------------------------------------------------
int a, b; | unknown | unknown | - |
int result; | unknown | unknown | unknown |
| | | |
a = 5; | 5 | unknown | unknown |
b = 2; | 5 | 2 | unknown |
a = a + 1; | 6 | 2 | unknown |
result = a - b; | 6 | 2 | 4 |
|
a = a + a, would a be equal to 12 ? and does it have different outcomes if i change the order ? |
|
|
|