Operators in C++

C++ operators are a special type of functions or symbols that take one or more than one arguments and create a new value or in other words used to perform various logical and mathematical manipulations or calculations.


 


They act as the foundation of C++ programming, languages such as C or C++ is incomplete without operators. C++ consists of a list of operators that are divided into groups such as:

  • Arithmetic Operators (+,-,*, /, %)
  • Unary operator(++, –)
  • Assignment Operator(=,+=)
  • Relational Operators (<,>,>=, <=,! = ,==)
  • Ternary operators (?:)
  • Bitwise Operators(&,<<,>>,~,^,|)
  • Logical Operators(&&, ||)
  • Misc Operator (sizeof(),*,?:,&,)
  • Ternary Operator

List of Operators present in C++

OperatorsSyntax
Assignment operatorsP=r
SubtractionP-r
AdditionP+r
Divisionp/r
Multiplicationp*r
Unary minus-r
Unary plus+r
Modulop%r
Decrement operator (pre, post)--r, r--
Increment operator (pre, post)++r, r++
!ERROR! unexpected operator '='p == r
Not equal top != r
Less than<
Greater than>
Less than equal to<=
Greater than equal to>=
Logical orp || r
Logical not!p
Addition Assignmentp += q
Scope Resolution operatorsp :: q
Division AssignmentP /= q
Logical andp && q
Commap,r

Following is the simple program on operators

#include<iostream>

// Main Function

using namespace std;

int main ()

{

// Variable Declaration

  int p = 38;

  int r = 20;

  int z = 40;

  int q = 60;

  int result;

  cout << " Operators Example Program \n";

  result = p - r; // subtraction  ( Subtraction or unary minus Arithmetic Operator)

  cout <<"\np - r = "<<result;

  result = r * z; // multiplication ( Multiplication Arithmetic Operator)

  cout <<"\nr * z = "<< result;

  result = p / z; // division ( Division Arithmetic Operator)

  cout <<"\na / c = "<< result;

  result = p + r * z; // precedence ( Addition or unary plus Arithmetic Operator)

  cout <<"\np + r * z = "<< result;

  cout <<"\np * r + z * q = "<< p * r + z * q; // Mixed

  return 0;

}

Result:

Operators Example Program

p – r = 18

r * z = 800

a / c = 0

p + r * z = 838

p * r + z * q = 3160

Coding Tag

Coding Tag always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

avatar
  Subscribe  
Notify of