Website For Developers

Operators in C++

Operators are the symbols which are used in C++ programming to do the math work or to do calculations in it.
All the symbols that are used in math can be used in C++ language with different functionality as well as the same functionality.
The operators in C++ are:
1- Arithmetic operators
2- Relational operators
3- Logical operators
4- Assignment Operators

Arithmetic operators in C++

Arithmetic operators are used to perform arithmetic calculations in C++. The operators are as follows

Operation Symbol Expression in C++
Addition + a+b
Subtraction - a-b
Multiplication * a*b
Divide / a/b

Relational operators

Relational operators are used to compare two values. It evaluates the values and then give the result in true or false that either the statement is true or false. The relational operators are given below in the table.
Suppose a, b, and c three different values having the values of 242, 555 and 242 respectively then:

Operation Symbol Expression Evaluation
Equal to (comparison) == a==c True
Less than < b<a False
Greater than > a>c False
Less than or equal to <= a<=b True
Greater than or equal to >= b>=a True
Not equal to != b!=a True

Logical operators

Logical operators are built by combining two relational expression to construct compound expressions.
Logical operators are as follows with their symbols used in C++:
    Logical AND (&&)
    Logical OR (||)
    Logical NOT (!)

Assignment operators

The assignment operator itself says it definition it means assign to. In C++ we need to store a value in a variable for that purpose we use the operator Assign to the symbol is “=”. For example you need to store the value of an area of triangle using the arithmetic operators the formula should be
Area == Base*height