Operators in C

Operators can be defined as basic symbols that help us work on logical and mathematical operations. Operators in C and C++, are tools or symbols that are used to perform mathematical operations concerning arithmetic, logical, conditional and, bitwise operations.



1. Arithmetic Operators
It includes basic arithmetic operations like addition, subtraction, multiplication, division, modulus operations, increment, and decrement.
The Arithmetic Operators in C and C++ include:
1) + (Addition) – This operator is used to add two operands.
2)– (Subtraction) – Subtract two operands.
3)* (Multiplication) – Multiply two operands.
4)/ (Division) – Divide two operands and gives the quotient as the answer.
5)% (Modulus operation) – Find the remains of two integers and gives the remainder after the division.
6)++ (Increment) – Used to increment an operand.
7)— (Decrement) – Used to decrement an operand.



2. Relational Operators
It is used to compare two numbers by checking whether they are equal or not, less than, less than or equal to, greater than, greater than or equal to.
1)== (Equal to)– This operator is used to check if both operands are equal.
2)!=  (Not equal to)– Can check if both operands are not equal.
3)> (Greater than)– Can check if the first operand is greater than the second.
4)< (Less than)- Can check if the first operand is lesser than the second.
5)>=  (Greater than equal to)– Check if the first operand is greater than or equal to the second.
6)<= (Less than equal to)– Check if the first operand is lesser than or equal to the second.

 

LOGICAL OPERATORS
It refers to the boolean values which can be expressed as:
-Binary logical operations, which involves two variables: AND and OR
-Unary logical operation: NOT
Logical Operators in C/C++ Includes –
1)&& (AND) – It is used to check if both the operands are true.
2)|| (OR) – These operators are used to check if at least one of the operand is true.
3)! (NOT) – Used to check if the operand is false
If the logical statement is satisfied (it is true), then the program will return the value 1, otherwise, if the relational statement is not satisfied (it is false), the program will return the value 0. 


4. Assignment Operators
It is used to assign a particular value to a variable. We will discuss it in detail in the later section with its shorthand notations.
1)=  (Assignment)- Used to assign a value from right side operand to left side operand.
2)+= (Addition Assignment)- To store the sum of both the operands to the left side operand.
3)-= (Subtraction Assignment) – To store the difference of both the operands to the left side operand.
4)*= (Multiplication Assignment) – To store the product of both the operands to the left side operand.
5)/= (Division Assignment) – To store the division of both the operands to the left side operand.
6)%= (Remainder Assignment) – To store the remainder of both the operands to the left side operand. 


5. Bitwise Operators
It is based on the principle of performing operations bit by bit which is based on boolean algebra. It increases the processing speed and hence the efficiency of the program.
The Bitwise Operators in C/C++ Includes –
1)& (Bitwise AND) – Converts the value of both the operands into binary form and performs AND operation bit by bit.
2)| (Bitwise OR) – Converts the value of both the operands into binary form and performs OR operation bit by bit.
3)^ (Bitwise exclusive OR) – Converts the value of both the operands into binary form and performs EXCLUSIVE OR operation bit by bit.
4)~ (One’s complement operator): Converts the operand into its complementary form.
5)<< – Left shift
6)>> – Right shift
7)AND – Both the operands should have boolean value 1 for the result to be 1.
8)OR – At least one operand should have boolean value 1 for the result to be 1.
9)XOR (EXCLUSIVE OR) – Either the first operand should have boolean value 1 or the second operand should have boolean value 1. Both cannot have the boolean value 1 simultaneously.


6. Miscellaneous Operators
Apart from the above-discussed operators, there are certain operators which fall under this category which include sizeof and ternary (conditional) operators.

1)sizeof – It returns the memory occupied by the particular data type of the operand
2)& (Pointer) – It refers to the address (memory location) in which the operand is stored.
3)*  (Pointer) –  It is a pointer operator
4)? (Condition) – It is an alternative for if-else condition



Posted on by