+15

# What does << & >> operator mean in C++ language?

//The Example Program is: #include <iostream> using namespace std; int main() { int a=8<<2; int b=8>>2; cout<<"a: "<<a<<endl; cout<<"b: "<<b; return 0; } //Output: a=32 & b=2; //What does << & >> operator mean? //Please Help me to understand it....... //Thanks in advance🙏

12/4/2018 1:09:26 PM

👑Sudeep Jaiswal

+4

<< operator: shift left >> operator: shift right 8 in decimal number = 1000 in binary number <<2 =100000 (in binary number) = 32 in decimal number 8 in decimal number = 1000 in binary number >>2 =0010 (in binary number) = 2 in decimal number

+12

They are overloaded operators which their functionality get determined by the context in which they appear. Since you've provided an example, it's clear that when you sending something to `ostream` via `<<` like this cout << "Interesting!"; the operator takes on "insertion" meaning and when using in a different context like so int a = 8 << 2; int b = 8 >> 2; it refers to shift-to-left and shift-to-right operators, respectively. Interesting note: If you want to perform the shift operation on-the-fly, you must wrap it in parenthesis just like this cout<<"b: "<< (8 >> 2) <<endl;

+9

They are bit shift operators: https://www.sololearn.com/learn/4086/?ref=app https://www.sololearn.com/learn/4087/?ref=app Let me know if anything in those lessons look confusing. :)

+5

+2

C++ Soldier (Babak) That's pretty cool. Had no idea they could be used like that. Maybe there's more to c++ than I thought.

+2

Temidayo Okiki Then why did you comment?

+2

2^5 2^4 2^3 2^2 2^1 2^0 32 16 8 4 2 1 8 << 2 move 2 places to left = 32 8 >> 2 move 2 places to right = 2

+2

<< and >> operators work two ways that is if used with cin and cout it is the function of input/output class i.e. cout<<x will display output the value of x on screen and cin>>x will take input value to store in x variable. when used as 8>>2 and 8<<2 it is used as right shift and left shift operator i.e. first integer "8" is the number taken in binary form and the second integer "2" is the number of places to shift the binary bits either to left or right. for example: 1 << 1 means: 00000001 changes to 00000010 1 << 6 means: 00000001 changes to 01000000

+1

New here i don't know it

+1

<<,>>operator are used after cout and cin to make use of them

+1

&ampersand means and for this operator value evaluate to be true conditions given on both side of it evaluates to true otherwise if none of condition is true or anyone is true the true it evaluate to false. For example. Suppose two identifiers are there ‘a’and’b’. So let suppose a condition. If(a<20&&b>20) Then if both the conditions are true a<20 And b>20 then whole condition is true but if anyone of the condition is false or both the condition is false then whole condition is false

+1

<<>>are called insertion and extraction operations respectively. >> is used with Cin(character input(extraction )) and << wifh cout (character output (insertion))

0

//The Example Program is: #include <iostream> using namespace std; int main() { int a=8<<2; int b=8>>2; cout<<"a: "<<a<<endl; cout<<"b: "<<b; return 0; } //Output: a=32 & b=2; //What does << & >> operator mean? //Please Help me to understand it....... //Thanks in advance

0

We love you too 海之妖

0

» _extraction operators(set form) & «_ insertion operators(put to) for example # include <upstream.h> int main( ) { cout«" addition program!"; int a,b; cout«"please enter value of a"; cin»a; cout«"please enter value of b"; cin»b; int c=a+b; cout«"the sum of the two numbers is =c"; cout«c; return 0; }

0

&& means "and"?

0

yep so something like if(a && b = 5) would return true if both a and b are 5 it would return false if either a or b were not 5

0

Ok I lied that would return an error correction: if(a && b == 5)

0

yes Ahmad AL-qorashi && means and || means or ! means not

-1