Operators in C - What are Operators in C programming?



What are Operators in C programming?

In today's tutorial series, we will learn about Operators.

 What is Operators in C programming - Explain Operators in C programming.

Operators are the most important parts in any programming language. Without this we cannot write any program. Just as brick is required to build a house, similarly we need
 Operators to make a program.

What is the Operators in C programming?

The operator is a symbol that tells the compiler to perform any mathematical and logical operation. There are a lot of built-in Operators in C programming.

Such symbols which are used to perform any type of mathematical and logical operation. They are called Operators in C programming. In programming, Operators are used 
to manipulate data and variables.

Operators work together with one or more variables, constants or operands. Variable, constant, operands, function and Operators merge all these together to form an expression.
A combination of operands and Operators is called Expression.
Operands are variables that together with Operators perform certain operations. Let us understand Expression by example.

Suppose an expression is given as "A + B - C * 6 + 3". In this, +, -, * these are all Operators while A, B, C are all these variables which are also called operands. 
And both 6 and 3 are constant whose value does not change. And when Variables, Operators, Constant, function are all added then the expression is ready.


Types of Operators in C - Types of Operators in C programming

As you read above, in C programming there are a lot of built-in Operators which have been divided into different types.

Which is as follows:


1.  Arithmetic Operators
2.  Assignment Operators
3.  Relational Operators
4.  Logical Operators
5.  Conditional Operators (Ternary Operators)
6.  Bitwise Operators
7.  Increment / Decrement Operators
8.  Special Operators 
Arithmetic Operators

Operator

Description
Example
+
This operator is used for add two operands
A + B = 5 + 3 = 8
-
This operator is used for subtract two operands
A - B = 5 - 3 = 2
*
This operator is used for multiply two operands
A * B = 5 * 3 = 15
/
This operator is used for divide two operands
A / B = 6 / 3 = 2
%
This operator is used for modulus division of two operands
A % B = 5 % 3 = 2












































Assignment Operators

Operators
Description
Example
=
Simple Assignment Operator. This operator is used to assign or store the value in a variable.
A = 5, C = A+B
+=
Add AND Assignment Operator. This operator appends the right operand with the value of left 
operand and then assigns that value to the 
left operand, ie stores the left operand.
C + = A This is equal to C = C + A.
-=
Subtract AND Assignment Operator. This operator subtracts the right operand from the left operand
 and then assigns its value to the left 
operand.
C - = A This is equal to C = C - A.
*=
Subtract AND Assignment Operator. This operator subtracts the right operand from the left operand 
and then assigns its value to the left 
operand.
C * = A This is equal to C = C * A.
/=
Divide AND Assignment Operator. It divides operator left operand from right operand and then stores 
its result in left operand.
C / = A This is equal to C = C / A.
%=
Modulus AND Assignment Operator. It stores the modulus results of the two operands in the left 
operand.

C% = A This is equal to C = C% A.




















Relational Operator


Relational Operator is used to compare the value of two operands hence it is also called Comparison operator. 


Operator
Description
==
This operator is called equal to operator. This operator is used to equal check two values. 
If both values ​​are equal then it returns true.
!=
This operator is called Not equal to operator. This is used to check that the two operands 
are not equal. Meaning that this operator is used to check the value of two operands, if the
 value of both operands is not equal then it returns true.
This operator is called Greater than operator. It is used to check the value of the first operand more than the value of the second operand. If the value of the first operand is greater than the value of the second operand then it returns true like (5> 2) return true
This operator is called Less than operator. It is used to check the value of the first operand less than the value of the second operand. If the value of the first operand is smaller than the value of the second operand then it returns true such as (3 <4) return true
>=
This operator is called Greater than equal to operator. It is used to check the value of the first operand greater than and equal to the value of the second operand. If the value of the first operand is greater than or equal to the value of the second operand, it returns true such that (5> = 5) return true
<=
This operator is called Less than equal to operator. It is used to check the value of the first operand less than the value of the second operand. If the value of the first operand is smaller than or equal to the value of the second operand, it returns true such that (5 <= 5) return true












Logical Operators

  • Logical Operators are used to combine two expressions and a condition. These Operators are used to perform logical operations. 

list of Logical Operators which are  in the table below.



Operators
Description
Example
&&
This operator is called Logical AND operator. This operator is used to check the output of two
 expressions. In this, if the output of both expressions is true then only it will return true otherwise 
False will return. Like A has value 5 store and B has value 3 store.
((A * B) == 15) && ((A + B) == 8)
Return true
||
This operator is called Logical OR operator. This operator is used to check the output of two expressions. In this, if one of the two expressions is output, it will return true, otherwise it will return False. Like A has value 5 store and B has value 3 store.
((A * B) == 15) || ((A + B) == 7)
Return true
!
This operator is called Logical NOT operator. This operator is used to reverse any logical state. If a condition is true, then the Logical NOT operator makes it false. Like A has value 5 store and B has value 3 store.
!((A * B) == 15) && ((A + B) == 8)
return false











Conditional Operators (Ternary Operators)

Conditional Operators are used to check the condition. This operator has only two options TRUE and FALSE. If the given condition satisfies, then TRUE will return otherwise FALSE will be return.

This operator is known by two names

  1. Ternary Operator ?
  2. Bitwise operator


Syntax of conditional Operators
Condition ? True Expression : False Expression;
Explanation:
• Question mark "?" Represents if part.
• The condition part gives us either one type of value either true or false.
If the condition part returns true value then true expression will execute. That is, the expression on the left side of ":" will execute.
• If condition part returns false value then False expression will be executed. That is, the expression on the right side of ":" will execute.

Bitwise Operator

Bitwise operator is used to manipulate BIT level data. This operator is used for shifting from right to left and left to right bit. The bitwise operator does not apply to float and double data type.
Computer only works on 0 and 1. The full form of Bit is a binary digit which is 0 and 1. The bitwise operator is calculated at 0 and 1. Whenever we manipulate the decimal number by bitwise operator, the processor first converts it to the form of 0 and 1 and then calculates it.

Operator
Description
&
Bitwise AND
|
Bitwise OR
^
Bitwise exclusive OR
<< 
Left Shift
>> 
Right Shift

Truth table of Bitwise operator &, |, ^

a
b
a & b
a | b
a ^ b
0
0
0
0
0
0
1
0
1
1
1
0
0
1
1
1
1
1
1
0

Increment / Decrement Operator

The Increment / Decrement operator is used to increase and Decrease the value of the variable once. For example, if the variable already has 5 value store, then its value will be reduced to 6 by increment operator and its value will be 4 by decrement operator.

     There are two types of increase / decrement operator.
  • Pre increment / decrement
  • Post increment / decrement
Pre increment / decrement operator

In the pre increment / decrement operator, first the value increase and decrease occurs and then the further calculation is performed.

Syntax of pre increment / decrement operator
++ (variable name), – – (variable name)

Post increment / decrement operator

In the pre increment / decrement operator, first the value increase and decrease occurs and then the further calculation is performed. 

Syntax of post increment / decrement operator
(variable name) ++, (variable name) – –

Special Operator

The special operator is used to perform special work. There are many special Operators in C programming whose lists are given here.

Operator
Description
Example
sizeof()
This operator returns the size of any variable according to its data type.
As a is an integer variable, 
it will return 4 or 2. According to 
different operating system
&
This returns the address of the operator variable.
& a; This will return the address of 
a.
*
The pointer variable is
*a used to denote.













Post a Comment

Please do not any spam link in the comment

Previous Post Next Post