b=a++; cout<<++b;Why ++b still equal to a++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

b=a++; cout<<++b;Why ++b still equal to a++?

int a=3; int b=2; b=a++; cout<<++b; Why is ++b's final vauel is 4 not 5?

23rd Aug 2018, 11:05 PM
billy.ying
2 Answers
+ 2
a=3 b=2 b=a++ -> 1st. b = a; 2nd. a = a+1 -> b = 3; a = 4 (increments after) cout << ++b -> 1st. b=b+1; 2nd. cout << b (increments before)
24th Aug 2018, 1:00 AM
Ruben Rodriguez
Ruben Rodriguez - avatar
0
a++ First returns the value then increments it. ++a Increments the value before returning it.
23rd Aug 2018, 11:45 PM
Theresa
Theresa - avatar