0

if a= 3 b= 2 b= a++ then cout of ++b will be what and how?

18th Jun 2016, 5:11 PM
SaiKrishna Swarna
3 Respostas
+ 3
it will be 4, here's why. when we declare a, it's 3. when we declare b it's 2. then we set the value if b to a++. now some people might read this and say okay it's setting b equal to a + 1, but that's not actually the case. what the computer reads is set be to a, then increment a. so right now, it's just b = 3. however when we say cout>>++b, the computer reads print increment b, so print b+1.so it will print 4. since ++ is treated as a mathematical operation it follows the same left to right rules. also, when doing increments using ++/--, always put them before the variable since it actually is executed a little faster than putting it after the variable.
18th Jun 2016, 5:17 PM
destro
+ 2
b=a++ //b=a a=a+1 ++b //b=b+1
18th Jun 2016, 5:16 PM
shine
0
thank you guys
18th Jun 2016, 5:20 PM
SaiKrishna Swarna