C Language Operator Types: Operators in C
Posted on January 25, 2010
Kind of Operator Types in C Programming Language
Operators:
An operator can be defined as a thing which is used to represent the operations or specific tasks and the objects of the operations are referred to as operands.
There are various types of operators :
1) Arithmetic operators
2) Logical operators
3) Relational operators
4) Increment and decrement operators
5) Conditional operators
6) Bitwise operators
Now we will look at these operator types one by one.
- Arithmetic Operators:
C provides five basic arithmetic operators for calculations like : addition, subtraction, multiplication, division and remainder which are +, -, *, / and % respectively. All these operators are called binary operators as these require two operands or values.
Arithmetic operators are divided into two types :
- Unary operators : acts on one operand only.
- Binary operators : acts on two operands.
| symbol | name | example | result | comment |
| + | addition | 5 + 2 | 7 | Adds values of operands |
| - | Subtraction | 5 – 2 | 3 | Subtracts values of operands |
| * | multiplication | 5 * 2 | 10 | Multiplies the values of two operands |
| / | division | 10 / 2 | 5 | Divides the value of left operand with right value |
| % | modulus | 3 % 2 | 1 | Checks the remainder |
The above table gives the complete idea of the binary operators.
- Logical Operators :
In this section we talks about the logical operators that refers to the ways in which the relationships can be connected. C provides three logical operators. These are :
| Symbol | name | example | result | comment |
| && | And | (6>3) && (5<8) | 1 | Result is true i.e. 1 as both expressions are true. |
| || | Or | (5>8) || (6>2) | 1 | Result is 1 as at least one expression is true. |
| ! | Not | !(4<=4) | 0 | Result is false. Negates the result of expression. |
- Relational Operators:
The relational operator determines the relation among different operands. C provides six relational operators for comparing numbers and characters. The following relational operators are:
| symbol | Name | Example | Result | Comment |
| == | Comparison | 5 == 3 | 0 i.e. false | Compares two values |
| < | Less than | 6 < 2 | 1 | Result is true |
| <= | Less than or equal to | 3 <= 10 | 1 | Result is true as 3 is less than 10. |
| > | Greater than | 6 > 5 | 0 | Result is false. |
| >= | Greater than or equal to | 6 > = 5 | 1 | Result is true as 6 is greater than 5. |
| != | Not equal to | 6 != 3 | 0 | Result is true. |
- Increment & Decrement Operator:
Increment operator is denoted by ++ and decrement operator is denoted by –.
The operator ++ adds 1 to its operand and — operator subtracts 1 from the operand.
In other words,
X = x + 1;
Is same as ++x or x++;
And
X = x – 1;
Is same as –x or x–;
- Conditional Operators :
Conditional operator stores a value depending upon the condition. This operator is ternary operator as it requires three operands.
General form is:
Expression1 ? expression2 : expression3
If expression1 evaluates to true i.e. 1, then the value of the whole expression is the value of expression2, otherwise the value of whole expression is the value of expression3.
- Bitwise Operators:
One of the powerful features of C is a set of bit manipulation operators. These permit the programmer to access and manipulate individual bits within a piece of data. The various bitwise operators are :
| operator | meaning |
| ~ | One’s complement |
| >> | Right shift |
| << | Left shift |
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR(exclusive OR) |
Now if we consider the values of A and B to be 20 and 15 then in binary format it will be represented as :
A = 0011 1100
B = 0000 1101
Then the bitwise operators will perform such operations :
1) A&B = 0000 1000
2) A|B = 0011 1101
3) A^B = 0011 0001
4) ~A = 1100 0011
Looking for a Fresher Job? Post Your Resume Free !!!
More Articles From "C Programming" Category
- Variable Types in C Programming Language
- Derived Data Types in C Programming Language
- C Programming Primary Constants: Integer, Real & Character
- Constants in C Programming Language: Primary & Secondary
- Storage Classes in C Programming Language: Auto, Register, Extern & Static Storage Types
- C Data Types: Range & Size
- Type Modifiers in C Language: signed, unsigned, long & short
- C Language Fundamental Data Types: Int, Float, Char, Double
- C Language Data Types
- C Language Keywords