- 1
Evaluate a+=a+ ++a if a=20
2 odpowiedzi
0
but can u tell me what will be the output of that
a += ++a + a++; (if a=20)
- 1
The result of the statement depends on the compiler. Clang++ gives "warning: unsequenced modification and access to 'a'." But g++ follows the following procedure.
Follow the precedence:
1. Pre Increment (++a)
2. Addition (+)
3. Assignment (+=)
'++a' means 'a = a + 1'. So, 'a' is now 21. Then the addition a + 21 means 21 + 21 which is 42 but you didn't store the result in 'a' yet. So, 42 is in a temporary variable and the value of 'a' is 21. Now the last assignment part, 'a += 42'. which is 'a = a + 42'. The value of 'a' is 21 so, the result is 63.