Operators in c language

AmitSingh377 5,807 views 18 slides Jun 23, 2014
Slide 1
Slide 1 of 18
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

No description available for this slideshow.


Slide Content

1

An operator is a symbol that tells the
computer to perform certain mathematical or
logical manipulations.
These operators are used in programs to
manipulate data and variables.
2

1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators (ternary operator)
7. Bitwise operators
8. Special operators
3

Arithmetic operators are used to perform numerical calculations
among the values.
OPERATOR MEANING
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
4

#include<stdio.h>
Main()
{
int x=25;
int y=4;
printf(“%d+%d=%d\n,x,y,x+y);
printf(“%d-%d=%d\n,x,y,x-y);
printf(“%d*%d=%d\n,x,y,x*y);
printf(“%d/%d=%d\n,x,y,x/y);
printf(“%d%%%d=%d\n,x,y,x%y);
5

Relational operator are used to compare two operands.
Operands may be variable, constant or expression.
OperatorOperator MeaningMeaning
< Is less than
<= Is less than equal to
> Is greater than
>= Is greater than equal to
== Equal to
!= is not equal to
6

#include<stdio.h>
void main()
{
int a, b;
printf(“Enter values for a and b : ");
scanf("%d %d", &a, &b);
printf("\n The < value of a is %d", a<b);
printf("\n The <= value of a is %d", a<=b);
printf("\n The > value of a is %d", a>b);
printf("\n The >= value of a is %d", a>=b);
printf("\n The == value of a is %d", a==b);
printf("\n The != value of a is %d", a!=b);
}
7

LOGICAL OPERATORS:
OPERATOR MEANING
&& Logical AND
|| Logical OR
! Logical NOT
These operators are used for testing more than one condition and
making decisions.
'C' has three logical operators they are:
8

Example:-Example:-
#Include<stdio.h>
void main()
{
int a, b;
printf(“enter values for a and b : ");
scanf(“%d %d", &a, &b);
printf("\n %d",(a<b)&&(a!=B));
printf("\n %d",(a<b)||(b<a));
printf("\n %d",!(A==b));
}
9

ASSIGNMENT OPERATORS
Assignment operator are used to assign
the value or an expression or a variable to
another variable.
 The syntax is
variablename = expression;
i.g. A=b;
 Operators:
== , += , -= , *= , /= , %= , >>= , <<= ,
&= ,
10

Increments & decrement operator is also called Unary .
The increment operator (++++) adder on to the variable and
decrement (- -- -) subtract one from the variable. There are
following unary operator
INCREMENT & DECREMENT INCREMENT & DECREMENT
OPERATORSOPERATORS
Operator Meaning
++x++x Pre increment
- -x- -x Pre decrement
x++x++ Post increment
X- -X- - Post decrement
11

INCREMENT & DECREMENT OPERATORS INCREMENT & DECREMENT OPERATORS
EXAMPLEEXAMPLE
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter the values for a and b :");
scanf("%d %d", &a, &b);
printf("\n The value of c is %d", c=++a);
printf("\n The value of c is %d", c=a++);
printf("\n The value of c is %d", c=--b);
printf("\n The value of c is %d", c=b--);
}
12

CONDITIONAL CONDITIONAL
OPERATORSOPERATORS
These conditional operator are used to construct
conditional expressions of the form.
Syntax:
exp1?exp2:exp3.
where exp1,exp2,exp3 are expressions.
Operator: ?: (ternary operator)
13

Example:-Example:-
#include<stdio.h>
void main()
{
int a, b, x;
printf("Enter the values of a add b : ");
scanf("%d %d", &a, &b);
x=(a>b)?a:b;
printf("Biggest Value is :%d",x);
}
14

Bitwise Operator:-Bitwise Operator:-
Are used by the programmer to communicate
directly with the hardware.These operator are
used for designing bit or shifting them either
right to left, left to right.
Example:-
OPERATOR MEANING
& Bitwise AND
| Bitwise OR
^ Bitwise Exclusive OR
<< Shift Left
>> Shift Right
15

SPECIAL OPERATORSSPECIAL OPERATORS
'C' supports some special operators such as comma
operator, sizeof operator and pointer pointer operators.
Comma operator:Comma operator:
the comma operator is used to combine related
expressions.
A comma linked list of expressions are evaluated
left to right and the value of right most expression is
the value of combined expression..
Example: value=(x=10, y=5, x+y);
16

Special Operators Special Operators
Contd…Contd…
Sizeof Operator:Sizeof Operator:
Sizeof is an operator used to return the
number of bytes the operand occupies.
Syntax:
m=sizeof(sum);
k=sizeof(2351);
17

18
Tags