Operators in C Language
Operator
An operator is a symbol that is used to operate in a given programming language. The operator specifies an operation to be performed. The operation produces a resultant value. Using operators the constant and variable are combined and expression is obtained. Then expression is solved according to the predefined rule of priority. Operators indicate the compiler to perform a specific type of operation. The operation can be arithmetic, logical, relational, bitwise, etc.
Types of Operator
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Bitwise Operator
- Assignment Operator
- Increment and Decrement Operator
- Conditional Operator
- Special Operator
Arithmetic Operator
An operator that performs an arithmetic operation such as
addition subtraction multiplication etc on operands is called an arithmetic operator.
They operate on two operands. Arithmetic operators require numeric values as operands.
It gives a numeric value as output. There are five arithmetic operators.
|
Operator |
Used |
|
+ |
Addition |
|
- |
Subtraction |
|
* |
Multiplication |
|
/ |
Division |
|
% |
Modulus |
Relational operator
The operator used to compare or determine the relation between two operands is called a relational operator.
The operands can be constant or variable. The comparison is of so many types
like whether two operands are equal or which one is greater and which one is
smaller. Relational operators are also called binary operators because they
operate on two operands. C language has six Relational operators.
Example
- < Less than
- > Greater than
- <= Less than equal to
- >= Greater than equal to
- == Equality
- != Not equal to
Assignment operator
Assignment operators are of two types
- Simple assignment operator
- Compound assignment operator
Simple assignment operator:- For this operator the sign of
equal to(=) is used. It is used to assign a value at the right-hand side of the =
operator to the variable at the left-hand side of =.
Compound assignment operator:- The compound assignment
operator used two operators simultaneously adjacent to each other that’s why
they are called compound operators.
Examples of compound operators are
1.
+=
2.
-=
3.
*=
4.
/=
5.
%=
Logical Operator
It is used to combine two or more relational operators. It
is used in a conditional expression. In C three logical operators are used. They
are
|
Operator |
Meaning |
|
&& |
AND |
|
“ |
OR |
|
! |
NOT |
And operator gives a result true when both operands
on which the end operator is applied are also true.
Or operator gives result proof when any operation on
which all operator is applied gives the result true.
Not operator the not operated by it is used to
reverse the value of the expression.
Bitwise Operator
The bitwise operator is the operator used to operate on the
data at the bit level. C support 6 bitwise operator. The bitwise operator
cannot be used with float and double. They apply to all types of integers.
|
Operator |
Purpose |
|
>> |
Right Shift |
|
<< |
Left Shift |
|
A |
Exclusive OR |
|
- |
Tilde |
|
& |
AND |
|
“ |
OR |
Increment and Decrement Operator
Increment operators are unary operators used to add 1 to the
operand value. The increment operator is denoted by the double plus symbol(++).
It has two types Pre increment and Posts increment operators.
The decrement operator is a unary operator which is used to
decrease the original value of the operand by 1. The decrement operator is
represented by the double minus symbol(--). It has two types Pre decrement and Posts decrement operators.
Conditional Operator
The conditional
operator is also known as a ternary operator. The conditional
statements are the decision-making statements that depend upon the output of
the expression. It is represented by two symbols, i.e., '?' and ':'.
The conditional
operator works on three operands, so it is also known as the ternary operator. The
behavior of the conditional operator is similar to the ‘if-else’ statement as the 'if-else'
statement is also a decision-making statement.
Special operator
C also includes some special operators which have specific
functionality. They include
- Comma operator
- & operator
- * operator
- size of the operator
Comma operator: It is used to combine many
expressions. The combined expression will be evaluated from left to right. The
comma operator is used in for loop.
& operator: It is also called an address operator.
It is used to print the address of any memory location.
Size of operator: it is used to measure the size of
memory occupied by any variable. The number of bits varies from variable to
variable.
* operator: It is also called an indirection operator.
It is a pointer operator used to declare a pointer-type variable. The pointer
is used to store the address of some variable.
Thanks for reading this article on Operator in C language hope you like it. Feel free to share it with your friend.
Tags
computerkisansaar
Operators
Operators in C - Types and Example
Operators in C Language
Types of operator
