Operators and Expressions
Operators and Expressions
Operators : Operators are signs/symbols used to perform certain task. (or operation)
OR
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations.
C++ has rich set of built-in operators. The following types of operators are studied in our
course.
• Arithmetic Operators (-,+,*,/,%)
• Relational Operators ( >, >= ,<= ,= =, != )
• Logical Operators ( !, ||, &&)
• Assignment Operator (=)
• Shorthand Operators (Arithmetic Assignment Operator) ( +=, –=, *=, /=, %=)
• Unary Arithmetic Operator (+ / – )
• Increment/Decrement Operators (++ / – –)
• Ternary Operator (Conditional Operator)
• Special Operators
Arithmetic Operators : There are five basic Arithmetic operator. They are +, –, *, /, % The
operation of these is as shown below :
If variable A holds value 15 and variable B holds value 25 , then,
Relational Operators : There are six relational operators in C++ language. They are
• Greater than (>)
• Greater than or equal to (>=)
• Less than (<)
• Less than or equal to (<=)
• Equal to (==)
• Not equal to ( != )
Assume variable A holds 10 and variable B holds 20, then –
Logical Operators : There are three logical operators in C++ language. These operators are
used to check the condition between two values.
They are AND (&&), OR ( || ) , NOT (!)
Assignment Operator (=) :
Shorthand Operators :
• This operator is also called Arithmetic Assignment Operator)
• This operator is applicable to Arithmetic Operators
• There are five Shorthand Operators
viz : +=, – =, *=, /=, %=
• They are used as shown in below table :
Operator Symbol Name of Operator Example Equivalent Construct