8 Answers
New Answer8 Answers
New AnswerThe 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
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
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message