Thanks for Visiting here

Operators
An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc.
There are following types of operators to perform different types of operations in C language.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operator
- Assignment Operator
- Misc Operator
1. Arithmetic Operators
The C language supports all the basic arithmetic operators such as addition, subtraction, multiplication, division, etc.
Operator | Description | Example(where |
---|---|---|
+ | adds two operands (values) | a+b |
- | subtract second operands from first | a-b |
* | multiply two operands | a*b |
/ | divide numerator by the denominator, i.e. divide the operand on the left side with the operand on the right side | a/b |
% | This is the modulus operator, it returns the remainder of the division of two operands as the result | a%b |
++ | This is the Increment operator - increases integer value by one. This operator needs only a single operand. | a++ or ++a |
-- | This is the Decrement operator - decreases integer value by one. This operator needs only a single operand. | --b or b-- |
2.Relational Operators
The relational operators (or comparison operators) are used to check the relationship between two operands. It checks whether two operands are equal or not equal or less than or greater than, etc.
Operator | Description | Example |
---|---|---|
== | Checks if the values of two operands are equal or not. If yes, then the condition becomes true. | (A == B) is not true. |
!= | Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. | (A != B) is true. |
> | Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. | (A <= B) is true. |
3.Logical Operators
C language supports the following 3 logical operators.
Operator | Description | Example ( |
---|---|---|
&& | Logical AND | a && b , returns 0 |
|| | Logical OR | a || b , returns 1 |
! | Logical NOT | !a , returns 0 |
1.With AND operator, only if both operands are true, the result is true.
2.With the OR operator, if a single operand is true, then the result will be true.
3.The NOT operator changes true to false, and false to true.
4.Bitwise Operators
Bitwise operators perform manipulations of data at the bit level. These operators also perform the shifting of bits from right to left. Bitwise operators are not applied to float or double, long double, void, etc.
The following table contains the bitwise operators. There are 6 bitwise operators in the C language.
Operator | Description | |
---|---|---|
& | Bitwise AND | |
| | Bitwise OR | |
^ | Bitwise Exclusive OR (XOR) | |
~ | One's complement (NOT) | |
>> | Shift right | |
<< | Shift left |
5.Assignment operator
An assignment operator is used for assigning a value to a variable. The most common assignment operator is =
Operator | Example | Same as |
---|---|---|
= | a = b | a = b |
+= | a += b | a = a+b |
-= | a -= b | a = a-b |
*= | a *= b | a = a*b |
/= | a /= b | a = a/b |
%= | a %= b | a = a%b |
6.Misc Operator
Except for Arithmetic and Logical Operator, there are some special Operators provided by C language which performs special operations and description of them summarized in the following table.
Operator | Description | Example |
---|---|---|
sizeof() | Returns the size of a variable. | sizeof(a), where a is integer, will return 4. |
& | Returns the address of a variable. | &i; returns the actual address of the variable. |
* | Pointer to a variable. | *i; indicate a pointer variable i. |
? : | Conditional expression. | i==1?”Y”:”N”; If condition is true then value Y otherwise value N. |