+ 3
please explain
What is the output of the following code? int a=3; int b=2; b=a++; cout<<++b; the answer was 4 but why, a plus 1 is 4 if b=4 plus 1 its 5 its 4 just if you don't add the last line ++b
2 Respuestas
+ 10
a = 3
b = a++ //b takes the value 3 because you're using a postfix ++, postfix first return value 3 then increment it to 4
cout << ++b // now you're using prefix, first increment the value b = 3, then return it, b=4