Saturday, November 3, 2018

Operators in C++ by 124study.blogspot.in

Operators in C++ by 124study.blogspot.in

operators in C++

Types of operators

  1. Assignment Operator
  2. Mathematical Operators
  3. Relational Operators
  4. Logical Operators
  5. Bitwise Operators
  6. Shift Operators
  7. Unary Operators
  8. Ternary Operator
  9. Comma Operator

Assignment Operator ( = )


Mathematical Operators

int x=10;
x += 4 // will add 4 to 10, and hence assign 14 to X. 
x -= 5 // will subtract 5 from 10 and assign 5 to x.

Relational Operators

int x = 10;  //assignment operator
x=5;         // again assignment operator 
if(x == 5)   // here we have used equivalent relational operator, for comparison
{
 cout <<"Successfully compared";
}    

Logical Operators


Bitwise Operators


Shift Operators

  1. Left Shift Operator <<
  2. Right Shift Operator >>
  3. Unsigned Right Shift Operator >>>

Unary Operators


Ternary Operator

int a = 10;
a > 5 ? cout << "true" : cout << "false"

Comma Operator

int a,b,c; // variables declaration using comma operatora=b++, c++; // a = c++ will be done.

0 comments:

Post a Comment