# operator

## What is an operator in mathematics and programming?

In mathematics and computer programming, an operator is a character that represents a specific mathematical or logical action or process. For instance, "x" is an arithmetic operator that indicates multiplication, while "&&" is a logical operator representing the logical AND function in programming.

Depending on its type, an operator manipulates an arithmetic or logical value, or operand, in a specific way to generate a specific result. From handling simple arithmetic functions to facilitating the execution of complex algorithms, like security encryption, operators play an important role in the programming world.

Mathematical and logical operators should not be confused with a system operator, or sysop, which refers to a person operating a server or the hardware and software in a computing system or network.

## Operators and logic gates

In computer programs, Boolean operators are among the most familiar and commonly used sets of operators. These operators work only with true or false values and include the following:

These operators and variations, such as XOR, are used in logic gates.

Boolean operators can also be used in online search engines, like Google. For example, a user can enter a phrase like "Galileo AND satellite" -- some search engines require the operator be capitalized in order to generate results that provide combined information about both Galileo and satellite.

## Types of operators

There are many types of operators used in computing systems and in different programming languages. Based on their function, they can be categorized in six primary ways.

### 1. Arithmetic operators

Arithmetic operators are used for mathematical calculations. These operators take numerical values as operands and return a single unique numerical value, meaning there can only be *one* correct answer.

The standard arithmetic operators and their symbols are given below.

Symbol |
Operation |
Explanation |

+ |
Addition (a+b) |
This operation adds both the operands on either side of the + operator. |

- |
Subtraction (a-b) |
This operation subtracts the right-hand operand from the left. |

* |
Multiplication (a*b) |
This operation multiplies both the operands. |

/ |
Division (a/b) |
This operation divides the left-hand operand by the operand on the right. |

% |
Modulus (a%b) |
This operation returns the remainder after dividing the left-hand operand by the right operand. |

### 2. Relational operators

Relational operators are widely used for comparison operators. They enter the picture when certain conditions must be satisfied to return either a true or false value based on the comparison. That's why these operators are also known as *conditional* operators.

The standard relational operators and their symbols are given below.

Symbol |
Operation |
Explanation |

== |
Equal (a==b) |
This operator checks if the values of both operands are equal. If yes, the condition becomes TRUE. |

!= |
Not equal (a!=b) |
This operator checks if the values of both operands are equal. If not, the condition becomes TRUE. |

> |
Greater than (a>b) |
This operator checks if the left operand value is greater than the right. If yes, the condition becomes TRUE. |

< |
Less than (a<b) |
This operator checks if the left operand is less than the value of right. If yes, the condition becomes TRUE. |

>= |
Greater than or equal (a>=b) |
This operator checks if the left operand value is greater than or equal to the value of the right. If either condition is satisfied, the operator returns a TRUE value. |

<= |
Less than or equal (a<=b) |
This operator checks if the left operand value is less than or equal to the value of the right. If either condition is satisfied, the operator returns a TRUE value. |

### 3. Bitwise operators

Bitwise operators are used to manipulate bits and perform bit-level operations. These operators convert integers into binary before performing the required operation and then showing the decimal result.

The standard bitwise operators and their symbols are given below.

Symbol |
Operation |
Explanation |

& |
Bitwise AND (a&b) |
This operator copies a bit to the result if it exists in both operands. So, the result is 1 only if both bits are 1. |

| |
Bitwise OR (a|b) |
This operator copies a bit to the result if it exists in either operand. So, the result is 1 if either bit is 1. |

^ |
Bitwise XOR (a^b) |
This operator copies a bit to the result if it exists in either operand. So, even if one of the operands is TRUE, the result is TRUE. However, if neither operand is TRUE, the result is FALSE. |

~ |
Bitwise NOT (~a) |
This unary operator flips the bits (1 to 0 and 0 to 1). |

### 4. Logical operators

Logical operators play a key role in programming because they enable a system or program to take specific decisions depending on the specific underlying conditions. These operators take Boolean values as input and return the same as output.

The standard logical operators and their symbols are given below.

Symbol |
Operation |
Explanation |

&& |
Logical AND (a&&b) |
This operator returns TRUE only if both the operands are TRUE or if both the conditions are satisfied. It not, it returns FALSE. |

|| |
Logical OR (a||b) |
This operator returns TRUE if either operand is TRUE. It also returns TRUE if both the operands are TRUE. If neither operand is true, it returns FALSE. |

! |
Logical NOT (!a) |
This unary operator returns TRUE if the operand is FALSE and vice versa. It is used to reverse the logical state of its (single) operand. |

### 5. Assignment operators

Assignment operators are used to assign values to variables. The left operand is a variable, and the right is a value -- for example, x=3.

The data types of the variable and the value must match; otherwise, the program compiler raises an error, and the operation fails.

The standard assignment operators and their symbols are given below.

Symbol |
Operation |
Explanation |

= |
Assignment (a=b) |
This operator assigns the value of the right operand to the left operand (variable). |

+= |
Add and assign (a+=b) |
This operator adds the right operand and the left operand and assigns the result to the left operand. Logically, the operator means a=a+b. |

-= |
Subtract and assign (a-=b) |
This operator subtracts the right operand from the left operand and assigns the result to the left operand. Logically, the operator means a=a-b. |

*= |
Multiply and assign (a*=b) |
This operator multiplies the right operand and the left operand and assigns the result to the left operand. Logically, the operator means a=a*b. |

/= |
Divide and assign (a/=b) |
This operator divides the left operand and the right operand and assigns the result to the left operand. Logically, the operator means a=a/b. |

%= |
Modulus and assign (a%=b) |
This operator performs the modulus operation on the two operands and assigns the result to the left operand. Logically, the operator means a=a%b. |

### 6. Increment/decrement operators

The increment/decrement operators are unary operators, meaning they require only one operand and perform an operation on that operand. They sometimes are called *monadic operators*.

The standard increment/decrement operators and their symbols are given below.

Symbol |
Operation |
Explanation |

++ |
Post-increment (a++) |
This operator increments the value of the operand by 1 after using its value. |

-- |
Post-decrement (a--) |
This operator decrements the value of the operand by 1 after using its value. |

++ |
Pre-increment (++a) |
This operator increments the value of the operand by 1 before using its value. |

-- |
Pre-decrement (--a) |
This operator decrements the value of the operand by 1 before using its value. |

*See also:* *proximity operator**, **search string**,* *logical negation symbol**, **character** and **mathematical symbols**.*