what is the output of the following code? Q: int a=3 int b=2 a=b++ cout<< ++b=____? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

what is the output of the following code? Q: int a=3 int b=2 a=b++ cout<< ++b=____?

what is the answer of this question and how??

17th Jul 2016, 7:37 PM
Rohan Das
9 Answers
+ 4
but if we considere the missing ";" int a=3; int b=2; a=b++; //so first assign a to b then incrément b (post inc) // a=2 and b= 3 cout<<++b; // son first increase b then cout it (pré inc) // b=4 and 'couting' 4 at screen PS : dont hesitate to test your code in the code playground
17th Jul 2016, 8:02 PM
Dorian
+ 2
You do not need to care bout a since it is not used but only the fact b is incremented on setting a then we prefix increment b, then output it so the answer is 2+1+1= 4
17th Jul 2016, 11:28 PM
_Geometry dash_ _Roh_ (AKA NovaRate0315)
_Geometry dash_ _Roh_ (AKA NovaRate0315) - avatar
+ 2
b is 4
18th Jul 2016, 3:38 PM
Karan Luther
Karan Luther - avatar
+ 1
1 increments in b
17th Jul 2016, 7:47 PM
Kashif Ahmed
Kashif Ahmed - avatar
+ 1
the output is compilation error :)
17th Jul 2016, 7:53 PM
Dorian
0
3
17th Jul 2016, 7:38 PM
Kashif Ahmed
Kashif Ahmed - avatar
0
how??
17th Jul 2016, 7:45 PM
Rohan Das
0
error
18th Jul 2016, 12:57 AM
Kamal Singh
Kamal Singh - avatar
0
b is 4
13th Aug 2017, 5:17 PM
Arun Kashyap
Arun Kashyap - avatar