explain different types of operators in c language
Answers
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. 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
Misc Operators
We will, in this chapter, look into the way each operator works.
Arithmetic Operators
The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 10 and variable B holds 20 then −
Show Examples
Operator Description Example
+ Adds two operands. A + B = 30
− Subtracts second operand from the first. A − B = -10
* Multiplies both operands. A * B = 200
/ Divides numerator by de-numerator. B / A = 2
% Modulus Operator and remainder of after an integer division. B % A = 0
++ Increment operator increases the integer value by one. A++ = 11
-- Decrement operator decreases the integer value by one. A-- = 9
Relational Operators
The following table shows all the relational operators supported by C. Assume variable A holds 10 and variable B holds 20 then −
Show Examples
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
Answer:
There are 6 Operators in the C language.
Explanation:
Operators:-
Operators are symbols used to carry out logical and Mathematical Operations. There are 6 Operators in the C language.
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Conditional Operator
- Bitwise Operator
- Assignment Operator
1. Arithmetic Operators:
Arithmetic Operators are used to carrying out Mathematical/Arithmetic Operations.
example:- Addition(+), Substraction(-), Multiplication(*), Division(/), Modulus(%).
There are types of Arithmetic Operators:-
- Binary Operator:- Operators that operate or work with an unmarried operand are unary operators.
- Unity Operator:- Operators that operate or work with operands are binary.
2. Relational Operator:-
A relational Operator is used for the assessment of the values of operands.
- Equal to(==)
- Not Equal to(!=)
- Greater Than(>)
- Less Than(<)
- Greater than or equal to(>=)
- Less than or same to(<=)
3. Logical Operator:-
Logical Operators are used to mix extra conditions/constraints or to supplement the assessment of the unique circumstance in consideration.
- AND Operator(&&)
- OR Operator(||)
- NOT Operator(!)
4. Conditional Operator:-
A conditional Operator is likewise referred to as a ternary operator. This operator is used to assemble conditional expressions.
example:- Condition1, Condition2, Condition3
5. Bitwise Operator:-
Bitwise Operator is used to carry out bit Operations among operators.
- Binary Left Shift Operator(<<)
- Binary Right Shift Operator(>>)
- Binary Ones Complement Operator(~)
- Binary AND Operator(&)
- Binary XOR Operator(^)
- Binary OR Operator(/)
6. Assignment Operator:-
Assignment operators are used to assigning value to a variable.
- Assign Operator(=)
- Increment then Assign(+=)
- Decrement then Assign(-=)
- Multiplies then assign(*=)
- Divides then assign(/=)
- Modulus then assigns (%=)
- Left shift and assign(<<=)
- Right shift and assign(>>=)
#SPJ3