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:
- Arithmetic operators
- Relational operators
- Logical operators
- Assignments operators
- Increment and Decrements operators
- Conditional operators
- Bit wise operators
- Special operators
|%||Modules Operators to get reminder in integer division||10%3||1|
Program based on Arithmetic Operators.
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);
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
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:
|<=||Less Than or equal to||10<=7||False|
|>=||Greater than or equal to||15>=10||True|
|!=||Not Equal to||3!=5||True|
Program based on Relational Operators:-
int num1 = 30;
int num2 = 40;
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);
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
- 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:
int l=2, m=5, n= 3; clracr();
if(l>m && l>n) // Logical operator and
printf(“\n First number is max=%d”, l);
printf(“\n Second Number is max=%d”,m);
printf(“\n Third Number is Max=%d”,n);
Second Number is Max= 5
- 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|
# include <stdio.h>
Total+=i; // This is same as Total = Toatal+i
printf(“Total = %d”, Total);