Operators in C programming language

Operators in C programming language

Social Shares
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Operators in C programming language

Hello visitors, in the last session you have learnt What is the flowchart, it’s processing. Now today we are going to learn about Operators in C programming language. By using these operators you can perform various types of operations on those variables by having values stored inside the variables. For example, by having value store inside two integer variables you can perform the operation of addition and print the sum of values of those two variables. Similarly, you can do more with different operations variables.

To perform operations with variables, you have to use different operators in C programming language. In this chapter, you are being told about such operators.

The variables that are used with operators in Operations are called operand. For example, see the statement given below.

 

c = a + b;

In the above statement, a and b have been used with the operator (+), so these two variables will be called operands.

Operators in C programming language are of 2 types.

  1. Unary – This type of operators is used only with a single operand.
  2. Binary – 2 operands are used with this type of operators.

Now let’s try to know about different operators who are using C language.

Operators in C programming language

Arithmetic operators in C programming language

Arithmetic operators are used to performing mathematical operations. Such as addition, subtraction, division and multiplication etc. Arithmetic operators in C programming language are of 5 types. These are basic mathematical operators.

 Operators
Description
+ (Addition)
This operator adds values of two variables.
– (Subtraction)
This operator subtract the value of one variable from the value of one variable.
* (Multiplication)
This operator multiply values of 2 variables.
/ (Division)
This operator divides the value of one variable from the value of another variable.
% (Modulus)
It is used to obtain the remaining value after the operator division.

 

Relational Operators

Relational operators in C programming language are used to comparing values of two variables. As you can use these operators, you can find out if the values of any two variables are equal and if not equal, then which variable is the value of which variable and the value of which variable is small.

Such operators in C programming language are used with conditional statements (if, if-else, switch, for, while etc.). These operators are used to check the condition. When the condition is true, the value becomes true and the value becomes false when the condition is false.

All the relational operators in C programming language are given below.

Operators
Description
== (Equal To)
This operator checks whether the values of both variables are equal.
!= (Not Equal To)
This operator checks whether values of both variables are non-equal.
<  (Lesser Than)
This operator checks whether the left operand is smaller than the value right operand.
> (Greater Than)
This operator checks whether the left operand is larger than the value right operand.
<=  (Lesser than equal)
This operator checks whether the left operand is equal to or equal to the value right operand.
>=  (Greater than equal)
This operator checks whether the left operand is greater than or equal to the value right operand.

Logical operators in C programming language

Logical operators are used with decision-making statements. These operators in C programming language are used to control two statements together in control statements. For example, you can check 2 conditions instead of one in an if statement. The following about the logical operators in C programming language.

Operators
Description
&&(AND)
When both conditions are true then the control statement value becomes true.
|| (OR)
When any one condition is true, the control statement value becomes true.
! (NOT)
These operators in C programming language are used with the same condition. When that condition is false then the control statement value becomes true.

 

Bitwise Operators

Bitwise operators in C programming language are used to perform bit-level operations on given variables. The decimal values of the variables are converted to bits. After this, the operations are performed on those bits.

Below is the following about bitwise operators in C programming language

 

Operators
Description
& (Bitwise AND)
This operator performs the AND operation with bits of the same position of both the variables.
| (Bitwise OR)
This operator performs an OR operation with bits of the same position of both the variables.
~ (Bitwise NOT)
These operators in C programming language are used only with one operand. All the bits of the value of the variable in which the variable is used with it goes opposite. As if 0 is 1 then it becomes 1 and then 1 becomes zero.
^ (XOR)
This is a special type of OR operator. This operator returns 1 return when the opposite is bits and returns 0 to the same bit.
<< (Left Shift)
This operator left-side of the variable’s bits in the left side of the variable in the variable of the right side shift.
>> (Right Shift)
The operator left-side of the variables in the variable of the right side of the variable as the shift in the right.

 

Operators in C programming language

 

As you know, work with bitwise operators bits. Let’s say you have created 2 variables a and b in the program. In these two variables, you have stored 3 and 5 values respectively. To work on their bits, firs,t you can convert them into binary.

3 = 00000011
5 = 00000101

They have been converted into binary only with the purpose of explaining to you. You do not need to insert binary values in the program. Store computer information only in binary form. All the operations defined above will be performed on these bits only.

 

Assignment Operators

Assignment operators are used to assigning values of variables to each other. Below are some of the different assignment operators in C programming language

Operators
Description
=
This assigns the operand value of operand right side to the operand of the left side.
+=
This operator assigns the value of the operand of the right side in the operand left side and assigns the operand with the result left-side. You can also write it in this way. a = a + b;
-=
This operator subtract the value of the operand of the right side of the operand from the left side of the operand and stores the result left side in the variable. You can also write it in this way. a = a-b;
*=
This operator stores the left side’s operand with the value of the operand value of the right side and stores the result in the operand of the left side.
/=
Divide the value of operator left operand with the value of right operand and stores the result in the operand of the left side.
%=
It separates the value of operand left side operand with the value of the operand of the right side and stores the remaining result in the operand of the left side.

 

Increment/Decrements operators

You can use increment/decrements operators in C programming language to increase or decrease the value of any variable instantly by a number. These are being given below.
 Operators
Description
 ++ (increment)
This is a unary operator. It increases the value of the operand by a number. When it seems before the operand, then the value is increment first and used later. When this operator operates after operand, the increment after the value of the operand is used.
 –(decrements)
This is also a unary operator. This decreases the value of the operand by one number. When it is used before the operand, the value decreases before the value is used. When it is used after the variable, the value is first used and later decreases.

 

Conditional Operator (?:)

The conditional operator is also called ternary operators in C programming language. This is a short form of the if-else statement. Its general structure is like this.

condition? statement1 : statement2;

 

If the condition is true then the statement will return one or the statement will return 2. An example of this is being given below.

5> 3? true: false;

Special operators in C programming language

Operators
Description
sizeof (var_name )
This operator returns the size of the variables in memory.
&
These operator returns the memory address of variables.
*
This operator returns the pointer of the variable.

 


Social Shares
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

3 comments

Leave a Reply

Your email address will not be published. Required fields are marked *