Operator:
an operator is a symbol or keyword
that tells the computer to perform certain mathematical logic calculations.
* ‘C’ provides a rich set of operators for making flexible and simple “expressions’.
* An expression is a sequence of oparants and operators. That reduces to a single value.
*Arithematic operator
*Relational operator
* Logical operator
* Assignment operator
* Increment/Decrement operator
* Bitwise operator
* Conditional operator
*Special operator
Arithmetic operator :
In C language the arithmetic operator are used to perform a mathematical calculation like addition(+), subtraction(-),multiplication(*),division(/),modular division (%).
* modular division produces the remainder of an integer. The sign of the result is always the sign of the operator.
Programme :
#include<stdio.h>
main()
{
Float a,b,add,sum,mul,div,Modu;
Printf(“enter the vlaue of b”);
Scanf(“%f”,&a);
Printf(“enter the vlaue of b”);
Scanf(%f”,&b);
add=a+b;
sub=a-b;
mult=a*b;
div=a/b;
modu=a%b;
Printf(“the values of add,sub,mul,div,modu:%f”,
a+b,a-b,a*b,a/b,a%b);
}
Assignment operator:
In C program the value for variables are assigned using the assignment operator.
* The most common assignment operater is used “-“
*These operator assign are copy the “left side value to Right side value”
Symbol Example Explanation
= a=10 10 is arrange for “a”
+= a+=10 a=a+10
-= a-=10 a=a-10
*= a*=10 a=a*10
/= a/=10 a=a/10
%= a%=10 a=a%10
Relational Operator:
Relational Operator is used to finding the relationship between two variables and also used to compare arithematic , logic, character, Expressions.
* The value of Relation Expression is either one or zero. If the result is “1” then the specified relation is true, “0” the specified is False.
Operator Meaning
< less than
<= less then equal
> greater than
>= greater than equal
== is equal
! = not equal
Logical operator:
Logical operators are gives when we want to test more than one condition and make a decision.
* The operator can consist of variables and expressions.
* There are three logical operators.
Operator meaning
&& Logical and
|| Logical or
! Logical not
Increment and Decrement operator : In C increment (++)Decrement(--) both operator are uniary operator (i.e) used on signal oparent
Write a programme to show the effect of increament order as suffix.
#include<stdio.h>
main()
{
Int a,z,x=10,y=20;
z=x*y++;
a=x*y;
printf(“%d%d”,z,a);
}
Write a program to show the effect of increament operator prefix.
#include<stdio.h>
Main()
{
Int a,z,x=10,y=20;
z=x*++y;
a=x*y;
printf(“%d%d”,z,a);
}
Bitwise operator:
Bitwise operators are used to performing at the Binary level. Decimal values are converted into Binaary values. These operators used for testing the tits. These operators are not applicable to Float or double.
* These operators can be performed only on integer operant such as int, char, longint.
Operation Meaning
<< left shift
>> Right shift
^ carat(Bitwise XOR)
~ Tilde conels complement
& Amphersend (Bits And)
! Bitwise(Or)
Write a program to shift input at data by two bit right.
#include<stdio.h>
Main()
{
Intx,y;
Printf(“Enter value x:”);
Scanf(“%d”,&x);
x>>=2
y=x
printf(“the right vlaue is =%d:y);
}
Conditional operator: Conditonal operator is used to consists a conditonal expression .
Syntax : ex1;ex2:ex3
Expression 1 is evaluated first
If it is true then the value of expression 2 becomes a value of conditional expressino If expression one is false, then the value of expression 3, becomes the value of the conditional expression.
Ex : x = (a>b)?a:b;
Special operator: coma operator , size of operator,pointer operator (&and* and member selection operator(. And -> )
Coma : cama operater are used to link related expression together.
Ex : value =(x=10,y=10,x+y)
coma operator also used in for loop.
(n=1,m=10,n<=m,n++,m++)
Size of operator: This operator is used to find the size of the variable or data type.
* This operator returns the number of bytes the operant occupied.
* The operant can be a variable, A constant is a data type identifier.
4 Comments
Excellent work
ReplyDeletePlease upload python
ReplyDeleteIt is very useful
ReplyDeleteNice and clear
ReplyDelete