In this article Operator in C we give the information about arithmetic operator, logical operator, assignment operators in C programming.

Operators in c:

C supports a rich set of built-in operators. Operators are used to modify data and variables in programs. They usually form part of mathematical or logical expressions.

C operators can be classified into several different categories. Like Follow:

  1. Arithmetic operators
  2. Relational operators
  3. Logical operators
  4. Assignments operators
  5. Increment and Decrements operators
  6. Conditional operators
  7. Bit wise operators
  8. Special operators

Arithmetic operators:-

Operators Meaning Example Result
+ Addition 5+2 7
Subtraction 10-8 2
* Multiplication 10*2 20
/ Division 10-5 2
% Modules Operators to get reminder in integer division 10%3 1

Program based on Arithmetic Operators.

#include<stdio.h>

#include<conio.h>
void main()
{
int p=10,q=3;
clrscr();
printf(“Addition of p, q is P+Q= : %d\n”, p+q);
printf(“Subtraction of p, q is P-Q= : %d\n”, p-q);
printf(“Multiplication of p, q is P*Q= : %d\n”, p*q);
printf(“Division of p, q is P/Q= : %d\n”, p/q);
printf(“Modulus of p, q is P%Q= : %d\n”, p%q);
getch();
}
O/p:-
Addition of p, q is P+Q=: 13
Subtraction of p, q is P-Q=: 7
Multiplication of p, q is P*Q=: 30
Division of p, q is P/Q=: 3
Modulus of p, q is P%Q=: 1

Relational operator: 

C supports a total of six relational operators.

Relational operators are used to compare two dimensions and make definite decisions based on their relationship.

If the specified receipt is true it returns one.

If the specified receipt is false it returns zero

Relational Operators such as follow:

Operators Meaning Example Result
< Less Than 10<5 False
> Greater Than 6>2 True
<= Less Than or equal to 10<=7 False
>= Greater than or equal to 15>=10 True
== Equal to 5==5 True
!= Not Equal to 3!=5 True

Program based on Relational Operators:-

#include<stdio.h>
#include<conio.h>
void main()
{
int num1 = 30;
int num2 = 40;
clrscr();
printf(“Value of %d > %d is %d”,num1,num2,num1>num2);
printf(“The Value of %d > =%d is %d”,num1,num2,num1>=num2);
printf(“Its Value of %d < %d is %d”,num1,num2,num1<num2);
printf(“Value of %d <= %d is %d”,num1,num2,num1<=num2);
getch();
}

Output :

Value of 30 > 40 is 0
The Value of 30 >=40 is 0
Its Value of 30 <=40 is 1
Value of 30 < 40 is 1

Logical operator:

  • In C, There are three logical operators such as follow
  • && means logical AND
  • || Semantic Logical OR
  • ! Semantic logical NOT
  • Logical Operators && and || Used when we want to examine more than one condition and make a decision

Program based on Logical Operators:

#include
#include
void main()
{
int l=2, m=5, n= 3; clracr();
if(l>m && l>n)   // Logical operator and
{
printf(“\n First number is max=%d”, l);
}
else
if(m>n)
{
printf(“\n Second Number is max=%d”,m);
}
esle
{
printf(“\n Third Number is Max=%d”,n);
}
getch();
}

Output:
Second Number is Max= 5

Assignments Operators:-

  • Assignments operators are used to assigns the result of an expression to a variable. we have seen the usual assignments operators,”=” .
  • C has a set of “shorthand” assignments operators of the form.
Simple assignment operators Shorthand operator
a=a+1 a+=1
a=a-1 a-=1
a=a*(m+n) a*=m+n
a=a/(m+n) a/=m+n
a=a%b a%=b

# include <stdio.h>
#include<conio.h>
void main()
{
int Total=0,i;
clracr();
for(i=0;i<=10;i++)
{
Total+=i; // This is same as Total = Toatal+i
}
printf(“Total = %d”, Total);
getch();

}

Output:

Total=55

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

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