What is << operator in cout | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

What is << operator in cout

below code outputs 2 instead of 11. why ? cout << (1<<1);

25th Mar 2018, 10:11 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
4 Answers
+ 10
because here 1<<1 act as left shift operator.. 1<<1 value is 2 and 2 print by cout..
25th Mar 2018, 10:29 AM
Scooby
Scooby - avatar
+ 8
<< is bitwise left shift operator The left-shift operator causes the bit pattern in the first operand to be shifted to the left by the number of bits specified by the second operand. So 1 << 1 = `0000 0010` evaluates to 2
25th Mar 2018, 10:31 AM
Manorama
Manorama - avatar
+ 3
never come across this operation...any usecase of same will be helpful to make me digest this easily
25th Mar 2018, 10:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
<< operator is also called as insertion operator
27th Mar 2018, 2:04 PM
Amrutha Addala
Amrutha Addala - avatar