Operators in C++
×

Operators in C++

3065

C++ operators are a special type of functions or symbols that take one or more than one argument 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:

  1. Arithmetic Operators (+,-,*, /, %)
  2. Unary operator (++,-)
  3. Assignment Operator (=,+=)
  4. Relational Operators (<,>,>=, <=,! = ,==)
  5. Ternary operators (?:)
  6. Bitwise Operators (&,<<,>>,~,^,|)
  7. Logical Operators (&&, ||)
  8. Misc Operator (sizeof(),*,?:,&,)
  9. Ternary Operator


List of Operators present in C++

OperatorsSyntax
Assignment operatorsP=r
SubtractionP-r
AdditionP+r
DivisionP\r
MultiplicationP*r
Unary plus+r
Modulo--r,r--
The decrement 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



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments