0

I don't understand how the output becomes 16. Can someone explain

https://code.sololearn.com/cKcI6tpsSqZw/?ref=app

13th Sep 2020, 7:44 PM
T-Legion
T-Legion - avatar
6 Réponses
+ 2
Step-by-step explanation: int a = 2; int b = 0; We declared two variables, you see. cout << ++b; Guess what it'll show... 1 But afterwards if we ask it again: cout << b; It will show... 1 again. Why? Because ++b means b = b + 1, not just b + 1; ++b changes the value of b whenever you use it. When you say b = ++a it works so: ++a => a = a + 1 => a = 2 + 1 => a=3 b = a => b = 3 The same staff with c: c = ++b => b was 3, and becomes 4, c = b => c = 4 Last string is 4*4 = 16; Better check the theory of increment and decrement. There are some aspects you should know but that is for another topik.
13th Sep 2020, 8:40 PM
globus
globus - avatar
+ 3
int a = 2 checked int b = ++a // a=3 b=3 because a is a+1 and it becomes 3 before declaring b int c = ++b// c=4 b=4 same thing at the above b was 3 and now it is b+1 before declaring c it is 4 We call it prefix you can read about it
13th Sep 2020, 8:02 PM
Yahya Bey
Yahya Bey - avatar
+ 1
You increase b while increasing c so the both of them become 4
13th Sep 2020, 7:52 PM
Yahya Bey
Yahya Bey - avatar
+ 1
Thanks. I failed it in a challenge. Now i get it
13th Sep 2020, 8:44 PM
T-Legion
T-Legion - avatar
0
Can you make comments on the code. I still don't understand
13th Sep 2020, 7:58 PM
T-Legion
T-Legion - avatar
0
Thanks for explaining
13th Sep 2020, 8:36 PM
T-Legion
T-Legion - avatar