## What are Operators in Programming?

An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.

• Operators are used in expressions.
• An expression is an instruction that combines one or more operands, zero or more operators, and zero or more pairs of parentheses.
• Operands are the terms on which an operator performs an operation and gives a result.
• So, the expression “a+b” can be broken down into the following three components:
• a, which is the left operand
• the plus symbol (+), which is the operator
• b, which is the right operand

An operator in computer programming is a symbol that has a defined function. An operator tells the compiler or interpreter to perform specific mathematical, logical, or other operations—or manipulations—on the operands to arrive at a result.

## How many are the Basic Operators?

Before learning about the basic operators used across computer programming languages, let’s first look at the types of operators and how they are categorized. Operator types and categories are depicted in the diagram below:

The classification of operators into unary, binary and ternary is based on the number of operands an operator requires.

Unary operators operate on a single operand. The increment operator (++) and the decrement operator (--) are examples of unary operators. The table below describes these operators:

### Unary operators

Unary operators operate on a single operand. The increment operator (++) and the decrement operator (--) are examples of unary operators. The table below describes these operators:

### Binary operators

Binary operators operate on two operands. The addition operator (+) and the division operator (/) are examples of binary operators.

The following are the five types of binary operators used in computer programming:

• Arithmetic
• Logical
• Bitwise
• Relational
• Assignment

Arithmetic Operators perform arithmetic operations. The table below describes the arithmetic operators:

Logical operators combine two or more conditions and return a Boolean value as the result.

Note: An exception among the logical operators is that logical NOT is a unary operator.

The table below describes the logical operators:

Relational operators compare values and return a Boolean value as the result. The table below describes the relational operators:

Bitwise operators use the binary representations of the operands and perform the indicated operation on each corresponding bit.

Note: An exception among the bitwise operators is that bitwise NOT is a unary operator.

The table below describes the bitwise operators:

Assignment operators assign the result of the specified operation to the left operand; no additional variable is used to store the result. The simple assignment operator (=) assigns the value of the right operand to the left operand. The table below describes the assignment operators:

Ternary operators operate on three operands. The conditional operator (?) is an example of a ternary operator. It uses the syntax (condition? option1: option2).

The conditional operator is an alternative to the if-else statement. The operator first evaluates the condition. If the condition is true, option1 will be the resultant value; if the condition is false, option2 will be the resultant value.

The following is an example of how the conditional operator can be used:

Suppose we need to find the larger number from among a and b.

Consider the expression num = (a > b) ? a : b

Here, num is the variable that will store the larger number from among a and b.

The expression can be evaluated thus: If a is greater than b, then num = a else num = b.

## Operator Precedence

In computer programming, knowledge of operator precedence and associative rules are essential. Operator precedence is similar to the PEMDAS rule in mathematics.

When two operators with different precedence are adjacent to each other in an expression, which operator should be evaluated first is based on the operator precedence rule.

When two operators with the same precedence are adjacent to each other in an expression, which operator should be evaluated first is based on associative rules—which tell the compiler whether it should evaluate from left to right (LR) or from right to left (RL).

The following table shows operator precedence and lists associative rules. The higher in the table an operator is, the higher its precedence.

## Context and Applications

This topic is significant for learning basics of programming and it is also important in professional exams for undergraduate courses especially for:

• Bachelor of Technology in Computer science
• Bachelor of Technology in Computer engineering
• Bachelor of Technology in Information Technology
• Bachelor of Engineering in Computer science
• Bachelor of Engineering in Computer engineering
• Bachelor of Engineering in Information Technology
• Bachelor of Computer Applications (BCA)

### Want more help with your computer science homework?

We've got you covered with step-by-step solutions to millions of textbook problems, subject matter experts on standby 24/7 when you're stumped, and more.
Check out a sample computer science Q&A solution here!

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

### Search. Solve. Succeed!

Study smarter access to millions of step-by step textbook solutions, our Q&A library, and AI powered Math Solver. Plus, you get 30 questions to ask an expert each month.

Tagged in
EngineeringComputer Science