- 2
what is the output of the following code? Q: int a=3 int b=2 a=b++ cout<< ++b=____?
what is the answer of this question and how??
9 Antworten
+ 4
but if we considere the missing ";"
int a=3;
int b=2;
a=b++; //so first assign a to b then incrément b (post inc)
// a=2 and b= 3
cout<<++b; // son first increase b then cout it (pré inc)
// b=4 and 'couting' 4 at screen
PS : dont hesitate to test your code in the code playground
+ 2
You do not need to care bout a since it is not used but only the fact b is incremented on setting a
then we prefix increment b, then output it so the answer is 2+1+1= 4
+ 2
b is 4
+ 1
1 increments in b
+ 1
the output is compilation error :)
0
3
0
how??
0
error
0
b is 4