Evaluate a+=a+ ++a if a=20 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Evaluate a+=a+ ++a if a=20

19th Feb 2017, 9:46 AM
Vitesh Topiwala
Vitesh Topiwala - avatar
2 Answers
0
but can u tell me what will be the output of that a += ++a + a++; (if a=20)
24th Aug 2017, 4:55 PM
shubham rathore
shubham rathore - avatar
- 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.
19th Feb 2017, 10:16 AM
Deleted