.

Operators in C++

The operators are the function which takes one or more parameters and gives new result. The operator is a symbol which tells the compiler to perform the mathematical and logical operations. Without the use of operator, the programming language like C or C++ is incomplete. There are different types of operators. They are

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

Arithmetic Operators

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

Example Progaram

Relational Operators

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

Example

Logical Operators

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

Example

Assignment Operator

Assignment operators are the operator that is used to assign the value to a variable. The left side of the assignment operator is a variable and the right side of the assignment operator is a value. The data type of left side variable and right side variable must be same if not the compiler will raise an error.

Example

Bitwise Operator

The bitwise operators are the operator similar to the logical operators, except the binary representations of data. Some of the operation performed in bitwise operator is addition, subtraction, multiplication and division.

Example

Misc Operators

Miscellaneous operator is the operator which is conditional and has 3 operands miscellaneous operator,. The first operand is always evaluated first followed by the second operand if it nonzero, then that is the value of result. Otherwise, the third operand is evaluated, and that is the value of the result. Exactly either one of the second and third operands is evaluated

Operator

Description

,

Comma operator

sizeof()

Returns the size of an memory location.

&

Returns the address of an memory location.

*

Pointer to a variable.

? :

Conditional Expression

Operators Precedence in C++

An operation is a mathematical calculation which involves zero or more input values (called operands) which produces an output value. Common operations (such as addition) use special mathematical symbols (such as +) which denotes the operation and these symbols are called operators. Operators in C++ perform the mathematical operations that return the value to the variable.

.