Operators in C Language
Operators are kinds of symbols that help us to do specific mathematical and logical computations. In other words, we can say that an operator operates operands.
For example, see the statement given below:
z = x + y;
Here, the “+” operator is known as Addition Operator and the ‘a’ and ‘b’ are operands. The Addition Operator tells the compiler to be added both operands ‘a’ and ‘b’.
If you are learning a programming language and do not have the concept of operators, then that programming language is incomplete because operators are the foundation of any programming language and C language is incomplete without operators.
Operators are used to manipulate data and variables in a program. In C language, we will read about different type operators.
Let’s see how many types of operators are there in C Language?
Types of Operators in C Language
Operators in C Language are of the following types:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise operators
- Assignment Operators
- Misc Operators or Other Operator
|Types of Operators||Operator Examples|
|Arithmetic Operators||+, -, *, /, %, ++, —|
|Relational Operators||==, >= , <= ,|
|Logical Operators||&&, ||, !|
|Bitwise Operator||&, |, ^, ~, >>, <<|
|Assignment Operators||=, +=, -+, *=, %=, &=|
|Misc Operators or Other Operator||sizeof(), ‘ , ‘ , ? :|
1. Arithmetic Operators
Arithmetic Operators are used to perform arithmetic operations such as Addition, Subtraction, Multiplication, Division, etc.
The following operators are covered under Arithmetic Operators -: (+, -, *, /,%, post-increment, pre-increment, post-decrement, pre-decrement).
There are two types of Arithmetic Operators.
- Unary Operators
- Binary Operators
#1) Unary Operators
Operators who perform mathematical operations on a single operand are called Unary Operators.
#2) Binary Operators:
Operators who perform mathematical operations on two operands are called Binary Operator.
2. Relational Operators
Relational operators are used to compare between two operands, such as to determine which of the two operands is larger and which is smaller, to determine whether one of the operands is equal to another of the operands.
Relational Operators provide the result as True or False. Some examples of Relational Operators are: (==,> =, <=)
3. Logical Operators
Logical Operators are used to combine two and more conditions. The result always gets Boolean value by Logical Operators which means the result is given as True or False and we consider True as 1 and False as 0.
For Example -: In C language Logical Operators (&&) returns true in the result when both conditions are satisfied and if both conditions are not satisfied then it returns False in the result.
Examples of Logical Operators are: (&&, ||,!) |
4. Bitwise Operators
Bitwise Operators are used to perform operations in the bit level between operands. Bitwise Operators first convert the operands to Bit and then perform the operation.
To perform fast processing of Mathematical operations like addition, subtraction, multiplication, etc is done at Bit-level by Bitwise Operators.
Examples of Bitwise Operators are: – (&, |, ^, ~, >>, <<)
5. Assignment Operators
Assignment Operators are used to assign a value to a variable. The operator on the left side of the Assignment Operators is the variable and the operator on the right side is the value that has to be stored in the left side operands (variable).
In Assignment Operators, the left side will be a variable, and the right side should also be the value of the same type because we can assign the same type of value in a variable.
If the operands on both sides are of different types then that value cannot be assigned in the variable and if we do this then there is a risk of data loss.
Some examples of Assignment Operators are: (=, + =, – +, * =,% =, & =)
6. Misc Operators or Other Operator
Apart from the above operators, there are some other operators available in the C language which are used to perform some specific tasks. Some of them are given below:
The sizeof operator is heavily used in the C/C++ programming language. It is a unary operator run in a compile-time that can be used to calculate the size of operands.
The result of sizeof operator is an unsigned integral type which is usually denoted by size_t. Basically, the sizeof operator is used to calculate the size of a variable.
Comma Operator is a binary operator that evaluates the first operand and provides the result, then evaluates the second operator and then returns its result. The Comma Operator has the lowest precedence in any C operator. The comma acts as both an operator and a separator.
Is Conditional Operator something like this Expression1? Expression2: Expression3. First of all, Expression1 is seen and then if Expression1 is true then Expression2 is executed, and if Expression1 is false. Then Expression3 is executed.
Read More -:
- Arithmetic Operators In C
- Relational Operators In C
- Logical Operators In C
- Bitwise Operators In C
- Assignment Operators In C
- Conditional Operator in C
Friends, I hope you have found the answer of your question and you will not have to search about the Operators in C Language
However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts.
If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.
Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the Operators in C Language
To get the information related to Programming Language, Coding, C, C ++, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.