- 1

[SOLVED] what is the output for the following codes

int a=3; int b=2; b=a++; cout<<++b;

5th Jul 2017, 7:37 AM
josh vlogs
josh vlogs - avatar
6 Respostas
+ 2
a=3, b=2 b=a++; <==> b=a; a+=1;// b=3, a=4 ++b; <==> b+=1;// b=4
5th Jul 2017, 7:42 AM
Jojo
+ 2
answer is 4 You can also run it to see it's solution..... I didn't see any problem in that....
5th Jul 2017, 7:57 AM
Deepanshu Soni
Deepanshu Soni - avatar
+ 1
4
5th Jul 2017, 7:40 AM
Loai Hazima
Loai Hazima - avatar
+ 1
that was my updated answer
5th Jul 2017, 7:41 AM
Loai Hazima
Loai Hazima - avatar
+ 1
woops sorry Loai
5th Jul 2017, 7:43 AM
Jojo
0
b=a++// this is post increment which means that b equal to a, then add 1 to a.. so b=3 cout<<++b; // this is pre increment which means add one first then print it to screen.(3+1=4)
5th Jul 2017, 8:16 AM
Dina
Dina - avatar