How to determine the output of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to determine the output of this code?

int a = 5 cout<< a++ + ++a

6th Jul 2016, 6:12 PM
Gowtham
1 Answer
+ 2
First, a copy of a is made, using the postfix notation. We have 5 to work with. Increment a. Now a = 6 but we are working with the old copy of a so... Value 5 is used as the first argument of operator+ function. Then we increment a(the incremented one, with value of 6), so now a is 7. Now we have the two needed arguments of the operator+ function, the old copy of a we made(with value of 5) and the newly incremented a(with value of 7) The expression that is being evaluated is 5+7 so the output should be 12.
6th Jul 2016, 7:04 PM
Garme Kain
Garme Kain - avatar