Operators in C language

In this tutorial, we will learn about what are operators and their types with example. There are different types of operators in the C language.

Operator and its types

An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical operations. There are 8 types of operators in the C language. 

Types of Operators in C language.

  1. Arithmetic Operators
  2. Increment and Decrement Operators
  3. Assignment Operators
  4. Relational Operators
  5. Logical Operators
  6. Bitwise Operators
  7. Conditional Operators
  8. Special Operators

Arithmetic Operators

An Arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division, etc on constants or variables.

OperatorMeaning of Operators
=This Operator used for the addition of two operands.
-This Operator used for the subtraction of two operands.
*This Operator used for the multiplication of two operands.
/This Operator used for the division of two operands.
%This is modulus operators that are used to get the remainder after division.
 

Example:


Output




Increment and Decrement Operators

There are two operators in C language Increment and Decrement. These two operators are used to increase or decrease the value of an operand by 1. 
Increment ++ operator increases the value by 1 whereas Decrement -- decreases the value by 1. These operators require only one operand to perform their operations 

Example:


Output




Assignment Operators

An Assignment operator is used for assigning the value to the variable. The commonly used assignment operator is =

OperatorDescriptionExample
=assigns values from right side operands to left side operanda=b
=+adds right operand to the left operand and assign the result to lefta+=b is same as a=a+b
-=subtracts right operand from the left operand and assign the result to left operanda-=b is same as a=a-b
*=multiply left operand with the right operand and assign the result to left operanda*=b is same a=a*b
/=divides left operand with the right operand and assign the result to left operanda/=b is same as a=a/b
%=calculate modulus using two operands and assign the result to left operanda%=b is same as a=a%b

Example:


Output




Relational Operators

A relational operator is used to check the relationship between two operands. A relational operator is true or false, if the relational operator is true it returns the value 1 otherwise it returns value 0. Relational operators are used in decision-making statements and loops

OperatorDescription
==check is two operands are equal
!=check is two operands are not equal
>check is operand on left is greater than operand on the right
<check if the operand on left is smaller than operand on the right
>=check if the operand on left is greater than or equal to the operand on the right
<=check if the operand on left is smaller than or equal to the operand on the right

Example


Output



Logical operator

Logical operators are used to combining two or more conditions. An expression containing a logical operator returns either 0 or 1 depending upon expression is true or false. Logical operators are used in decision making in C. There are 3 types of logical operators.

OperatorDescriptionExample
&&Logical AND(a&&b) is false
||Logical OR(a||b) is true
!Logical NOT(!a) is false

Example:


Output




Bitwise Operator

Bitwise operators perform manipulations of data at the bit level. These operators also perform shifting of bits from right to left. Bitwise operators are not applied to float and double Datatypes.

OperatorDescription
&Bitwise AND
|Bitwise OR
^Bitwise exclusive OR
<<left shift
>>right shift

Example:


Output



Conditional Operators

The conditional operator is actually the if condition that we use in decision making in C language but using conditional operator we turn if condition statement into a short and simple operator.
The syntax for the conditional operator is :

Special Operators

OperatorDescriptionExample
sizeofReturn the size of the variablesizeof(x) Return the size of the variable x
&Return the address of the variable&x; Return the address of the variable x
*Pointer to variable*x; will be Pointer to variable x


 

                                









Comments

Popular posts from this blog

How to install minGW-w64 on Windows 10

The History of C Programing.