- 4

If int a=3; int b=2; b=a++ cout <<++b,what is the output?

11th Mar 2017, 9:34 AM
Wis Vaurasi
Wis Vaurasi - avatar
8 Respostas
+ 16
The output will be 4. Here is how the logic works on your case: Given : a = 3 b = 2 Then : b = a++ which means take a value to b and then increment the a value. so b value is same as a (before the increment), so with that statement, their value become: b = 3 (same as a before increment) a = 4 (the value change because we got increment) Then evaluate the last statement: ++b => this means that we increment the value before we use the value. so in the end. so, cout << ++b; // will result: 4
11th Mar 2017, 10:05 AM
Dadang NH
Dadang NH - avatar
+ 5
It will produce 4 as output. Let us examine int a=3; int b=2; b=a++; // b=a++; => b = a; a = a + 1 so b = 3 cout <<++b //++b is prefix operator so value of b shall be // incremented before display
11th Mar 2017, 9:41 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 5
4
27th Mar 2017, 8:02 AM
Vishnu ks
Vishnu ks - avatar
+ 1
ans it will be 4
12th Mar 2017, 10:18 AM
Nagakiran D
Nagakiran D - avatar
0
thank you guys
12th Mar 2017, 11:31 AM
Wis Vaurasi
Wis Vaurasi - avatar
0
4
7th Sep 2019, 5:20 PM
ROHIT KAPSE
ROHIT KAPSE - avatar
- 1
thank you guys
12th Mar 2017, 11:31 AM
Wis Vaurasi
Wis Vaurasi - avatar
- 1
the ans = 2
8th Apr 2020, 11:07 AM
Mubaraq
Mubaraq - avatar