+ 4
Hello everyone please solve my problem. when be I use cout<<(1<<1 ); so answer is 2 and when be use cout<<(2<<2) then answer 8?
2 Respostas
+ 16
● Left shift operator works like this:
x << y equals to x * 2^y
2 << 2 equals to 2 * 2^2
equals to 2 * 4
equals to 8
● Right shift operator works like this:
x >> y equals to x / 2^y
8 >> 2 equals to 8 / 2^2
equals to 8 / 4
equals to 2
Also you have syntax error on the code at the following line:
`cout<<endl<<<(2<<2);`
Which should be:
`cout<<endl<<(2<<2);`
Notice that the `<<<` just before `(2<<2)` causes a problem.
Hth, cmiiw
+ 1
Sandeep 1+1*1=2then
2+2*2=8 it is the method of solving this