C++ Operators and Expressions

PREV     NEXT

What are operators?

The operators are the special type of functions that takes one or more parameters and gives new result. It is a symbol that tells the compiler to perform the mathematical and logical manipulations. The programming language like C or C++ is incomplete without the use of operators.

Some of the built in operators are

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Assignment operators
  • Bitwise operators

So, let us have a look all these operators briefly.

Arithmetic Operators

The arithmetic operators are used to perform the arithmetic operations on the operands. The operations can be addition, multiplication, subtraction and division.


Let us have a look at the example:

COMPILE & RUN

Relational Operators

The relational operators are those operators that are used to compare the values of two operands. For example, by comparing two operands that their values are equal or not, or the value of one operand is greater than the other.

Let us have a look at the example:

COMPILE & RUN

Logical Operators

The logical operators are those operators that are used to combine two or more conditions.  The logical operators are AND (&&) and OR (||). If we combine two statements using AND operator then only both the valid statements will be considered and if we combine two statements using OR operator then only either one of them will be considered.

Let us have a look at the example:

COMPILE & RUN

Assignment Operators

The assignment operators are those operators which are used to assign value to a variable. On the left side of the assignment operator the operand is a variable and the right side of the operator the operand is a value. The value on the right side of the operator should be of the same data type as of variable on the left side of the operator otherwise it will show a compile error.


Let us have a look at the example:

COMPILE & RUN

Bitwise Operators

The bitwise operators are those are used to perform bit level operations on the operands. In the bitwise operators first operators are converted to bit level and then calculation is performed on the operands. Some of the operations which are performed are addition, subtraction, multiplication, division, etc.

Let us have a look at the example:

COMPILE & RUN

What are expressions?

An expression is a sequence of operators and the operands. It is a form when you combine operands and operators.

The expressions are of three types

  • Arithmetic expression
  • Relational expression
  • Logical expression

Arithmetic Expression

An arithmetic expression is that expression in which arithmetic operators are used. Like addition, multiplication, subtraction, division, etc.

Relational Expression

A relational expression is that expression in which relational operators are used. The operators provided in relational expression are less than (<), greater than (>), less than equal to (<=), greater than equal to (>=), etc.

Logical Expression

A logical expression is that expression in which logical operators are used. Some of the logical operators are AND (&&), OR (||), NOT (!).

PREV     NEXT

Share this website !!!
Facebook Twitter Linkedin