Operators are the symbol which operates on value or a variable. C language is rich in built-in operators and provides the following types of operators -
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Other Operators
Arithmetic Operators
| Operator | Description |
| + | Addition |
| - | Subtraction |
| ∗ | Multiplication |
| / | Division |
| % | Modulus/Remainder |
Relational Operators
| Operator | Description | Example | Meaning |
| > | Greater than | x>y | x is greater than y |
| < | Less than | x<y | x is less than y |
| >= | Multiplication | x>=y | x is greater than or equal to y |
| <= | Division | x<=y | x is less than or equal to y |
| == | Modulus/Remainder | x==y | x is equal to y |
| != | Modulus/Remainder | x!=y | x is not equal to y |
- Relational Operators are used to compare two numbers
- if in a comparasion the condition is true then it returns 1.
- if given condition is false then it returns 0.
Logical Operators
| Operator | Description |
| && | Logical AND |
| || | Logical OR |
| ! | Logical NOT |
Logical Operators works on Logic gates. The below table can help to understand how logic gate works in C Language.(False - 0, True - 1)
| A | B | A&&B | A||B | !A |
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Bitwise Operators
Bitwise operator works on bits and performs bit-by-bit operation.
| Operator | Description |
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR |
| ~ | One's complement |
| >> | Right Shift |
| << | Left Shift |
Assignment Operators
| Operator | Description | Example |
| = | Assigns values from right side operands to left side operand | c = a + b, in this statement value of a+b assigned into c |
| += | Add right operand to the left operand and then assign it to left operand | a+=b is same as a=a+b |
| -= | Subtract right operand from the left operand and then assign it to left operand | a-=b is same as a=a-b |
| ∗= | Multiplies right operand with left operand and then assign it to left operand | a∗=b is same as a=a*b; |
| /= | Divides left operand with the right operand and then assign it to left operand | a/=b is same as a=a/b |
| %= | Calculate modulus using two operands and then assign it to left operand | a%=b is same as a=a%b |
Other Operators
| Operator | Description | Example |
| sizeof() | Returns size of variable. | sizeof(i), if i is integer then it will return 4. |
| & | Returns address of variable in memory. | &i; will return address of the variable. |
| * | Pointer variable. | *i; will declare a pointer variable. |
| ? : | Conditional Operator |
|
..
SHARE THIS