+ 1
Anybody please explain this code.
cout<<(2<<4<<3); Its output is 256 how?
3 odpowiedzi
+ 10
Above statement is equivalent to the below statement.
cout << ((2 << 4) << 3);
Left shifting is done from left to right first.
2 is left shifted 4 times which results in 32.
Then 32 is left shifted 3 times which results in 256.
+ 2
There "<<" in brackets is binary shift
2 << 4
2 equals 10 in binary
This operation do it like this:
000010->100000
Those operations has very low priority, so they program just makes this like:
((2<<4)<<3)
2<<4 is 32
32<<3 is 256(000100000->100000000)
0
Better search "binary operations c++", I can't describe this properly
I just can say that (1<<n) is 2 in power of n