Operators

Introduction

Operators are symbols which take one or more operands or expressions and perform arithmetic and logical computations based on the predefined priority and associativity. Operands are the objects upon which the operators operate to produce a new value. It can be a constant or variable. For example

int x = 5 * 7 + 9

Here multiplication (*), plus (+) and assignment (=) are operators, but 5 and 7 are operands. Multiplication enjoys the higher priority than plus and assignment operators, so, 5 * 7 is evaluated first. Then the result is added to 9 (because the plus enjoys the higher priority than the assignment operator) and, finally, the result 44 is assigned to x.


Types of Operators

There are different classifications of operators, as explained below:

Classification 1

This classification of operators is based upon the number of operands.

  • 1. Unary operators: These operators act upon a single operand to produce a new value. For example:
    x++;
  • 2. Binary operators: These operators act upon two operands to produce a new value. For example:
    x = x + 1;
  • 3. Ternary operators: These operators act upon three operands to produce a new value. For example:
    x = 10 > 5 ? 1 : 0;

Classification 2

The types of operators under this classification are:

  • 1. Arithmetic Operators
  • 2. Unary Operators
  • 3. Relational Operators
  • 4. Logical Operators
  • 5. Assignment Operators
  • 6. Conditional Operator
  • 7. Bitwise Operators
  • 8. Special Operatos

Rules of operators

All operators follow the following two rules:

  • 1. Precedence: It decides which operation would be performed first in an expression.
  • 2. Associativity: It decides the order of evaluation if more than one operator enjoys the same precedence. there are three different types of associativity, such as
    a. left-to-right
    b. right-to-left
    c. right-left / left-right

List of operators, precedence and associativity

img

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext