a=3,b=2 ,b=a++,cout <<++b; How 4? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

a=3,b=2 ,b=a++,cout <<++b; How 4?

18th Oct 2016, 10:12 AM
preeto kashyap
preeto kashyap - avatar
8 ответов
+ 6
You're setting B to A++, this means you're setting B to 3, as it is a post-increment. A then becomes 4 due to the post-increment. You then print out ++B, which is a pre-increment, so it increments before printing out it's value. So B becomes 4, thus the output is 4.
18th Oct 2016, 12:16 PM
Cohen Creber
Cohen Creber - avatar
+ 2
dont fool guys... b++ doesnt mean b+1+1... b++ is post increment.. so when b++ is execaute its remains b and in next turn it becomes b+1 and if it is pre-increment then before execauting value of b it was incremennted and use like... 6++ = 6,7,8,9.... in loop ++6 = 7,8,9,.... in loop
18th Oct 2016, 1:03 PM
Kashyap
Kashyap - avatar
+ 1
in this example... first b=a++.. here it ia post-increment.. so b=3 and after that cout<<++b so here it is preincrement... so the value will be 4
18th Oct 2016, 1:05 PM
Kashyap
Kashyap - avatar
+ 1
a++ evaluates to the old value of a, and increments a. ++b increments b and evaluates to the new value of b. Only after this code is evaluated will a be saved in the memory incremented. I recommend changing b = ++a; to see how it changes the code.
18th Oct 2016, 1:14 PM
Kyle Rasmussen
Kyle Rasmussen - avatar
0
I guess one + specifies +1 so answer is 4
18th Oct 2016, 11:19 AM
Neo Vraz
Neo Vraz - avatar
0
thanks guys
19th Oct 2016, 1:34 PM
boomidevi
boomidevi - avatar
- 2
if n=3. then n+ = n+1. similarly n++ = n+1+1 3+1+1=4. u can take this eg.
18th Oct 2016, 12:38 PM
Bromit
- 2
++b =1+1+2=4. do not forget to make my answer helpful
18th Oct 2016, 12:39 PM
Bromit