SlideShare ist ein Scribd-Unternehmen logo
1 von 30
COMPUTER PROGRAMING AND UTILIZATION
By Kaushal Patel
TYPES OF OPERATORS
Operators are the verbs of a language that help
the user perform computations on values.
“An operator is a symbol (+,-,*,/) that directs the computer to
perform certain mathematical or logical manipulations and is
usually used to manipulate data and variables”
Ex: a + b
Definition
2
Operators in C
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
3
Arithmetic operators
Arithmetic operators are used to perform arithmetic
operations. ‘C’ language supports following arithmetic
operators.
Operator example Meaning
+ a + b Addition –unary
- a – b Subtraction- unary
* a * b Multiplication
/ a / b Division
% a % b Modulo division-
remainder
4
 The ‘C’ language does not provide the operator for exponentiation.
+ and – operator can be used as unary operator also. Except %
operator all arithmetic can be used with any type of numeric
operands, while % operator can only be used with integer data type
only.
 Following program will clarify how arithmetic operators behave
with different data type, particularly the use of /and % operator.
Arithmetic operators
5
Example:-
# include<stdio.h>
main()
{
int x=25;
int y=4;
printf(“%d+%d=%dn” ,x, y, x+y);
printf(“%d-%d=%dn” ,x, y, x-y);
printf(“%d*%d=%dn” ,x, y, x*y);
printf(“%d/%d=%dn” ,x, y, x/y);
printf(“%d%%d=%dn” ,x, y, x%y);
}
Arithmetic operators
6
Output:-
25+4 =29
25-4=21
25*4=100
25/4=6
25%4=1
Arithmetic operators
7
Explanation:
First three operations are obvious. The division
operation gives the answer 6 because, the variables x and
y are integer variables, when we use / with integer
operands the result will be integer number.
while,%operator produce the remainder after division of
25by 4.
Arithmetic operators
8
Assignment Operators
 We have already used the assignment operator = in previous
programs ‘C’ language supports = assignment operator. It is used
to assign a value to a variable. The syntax is
variablename = expression
 The expression can be a constant, variable name or any valid
expression.
 ‘C’ also supports the use of shorthand notation also.
form is
variable = varname operator expression;
into
varname operator = expression;
9
Assignment Operators
 Use of shorthand notation makes your statement
concise and program writing becomes faster when
variable name are long in size
Assignment Operator Shorthand
a = a + 5; a += 5;
a = a – 5; a -= 5;
a = a * 5; a *= 5;
a = a /5; a /= 5;
a = a % 5(assuming a as integer) a %= 5;
10
Assignment Operators
 Example:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“Give the value of an”);
scanf(“%d”,&a);
a += 5;
printf(“a= %dn”,a);
a -= 5;
printf (“a =%dn”,a);
getch();
}
11
Assignment Operators
 Output:-
Give the value of a
4
a =9
a =4
12
Logical Operators
 Sometimes in programming, we need to take certain
action if some condition are true or false. Logical
operators help us to combine more than one conditions,
and based on the outcome certain steps are taken.
Operator name Meaning
&& Logical AND
|| Logical OR
! Logical NOT(Negation)
13
Logical Operators
 Logical NOT is an unary operator. In an expression, we can use more then
on logical operation. If more then one operator is used, !(NOT) is
evaluated first, then &&(AND) and then ||(OR), we can use parentheses to
change the order of evaluation.
for example, if we have a = 2, b = 3 and c = 5 then,
Expression Value Remark
a <b && c ==5 True Both expression are true
! (5 >3) False 5>3 is true & negation of
true is false
a< b || c=10 True a<b is true which makes
the expression true
(b> a) && (c !=5) False c =5, s0 second
condition false
(b<c || b>a) && (c==5) True Both sub expression are
true
14
Increment & Decrement Operators
C supports 2 useful operators namely
1. Increment (++)
2. Decrement(--)operators
The (++) operator adds a value 1 to the operand
The (--) operator subtracts 1 from the operand
(++a) or (a++)
(--a) or (a--)
15
Examples for (++) &(--) operators:-
Let the value of a =5 and b=++a then
a = b =6
Let the value of a = 5 and b=a++ then
a =5 but b=6
i.e.:
1. a prefix operator first adds 1 to the operand and then the result is
assigned to the variable on the left
ex:- (++a)or (--a) is called prefix increment or decrement
2. a postfix operator first assigns the value to the variable on left and
then increments the operand.
ex:- (a++)or (a--) is called postfix increment or decrement
Increment & Decrement Operators
16
If the ++ or – operator is used in an expression or
assignment then prefix notation give different values.
Ones should use prefix notation carefully in an
assignment or expression involving other variables.
Increment & Decrement Operators
17
Example:-
#include <stdio.h>
#include <conio.h>
main()
{
int x=10;
int y;
int z=0;
clrscr();
x++;
++x;
y=++x;
printf(“ Value of x=%d y=%d and z-%dn”, x,y,z);
z=y--;
printf(“ Value of x=%d y=%d and z-%dn”, x,y,z);
}
Increment & Decrement Operators
18
Output:-
Value of x=13 y=13 and z=0
Value of x=13 y=12 and z=13
Increment & Decrement Operators
19
C language has two useful operators called increment(++) and decrement
(--) that operate on integer data only.
The increment (++) operator increments the operand by 1, while the decrement
operator (--) decrements the operand by 1, for example ,:
int i , j;
i = 10;
j = i++ ;
printf(“ %d %d “, i, j);
OUTPUT:-
11 10 . First i is assigned to j and then i is incremented by 1
Increment & Decrement Operators
20
If we have :
int i, j ;
I = 20;
j = ++i;
printf(“%d %d”, i, j);
OUTPUT :
first i is incremented by 1 and then assignment take place i.e., pre- increment of i.
now, consider the example for (--) operator :
int a, b;
a=10;
b= a--;
printf(“%d %d”, a , b)
OUTPUT :
first a is assigned to b then a is decremented by 1. i.e.,post decrement takes place
Increment & Decrement Operators
21
Decrement Operator:-
If we have : int i, j ;
I = 20;
j = --i;
printf(“%d %d”, i, j);
OUTPUT : 19 19. first i is decremented by 1 and then assignment
take place i.e., pre-decrement of i.
Note : on some compilers a space is required on both sides of ++I or i++ ,
i-- or --i
Increment & Decrement Operators
22
Bitwise Operators
 We know that internally, the data is represented in
bits 0 and 1. ‘C’ language supports some operators
which can perform at the bit level. These type of
operations are normally done in assembly or
machine level programming. But, ‘C’ language
supports bit level manipulation also, that is why ‘C’
language is also known as middle-level programming
language.
23
Bitwise Operators
 Following table shows bit-wise operators with their
meaning:
Operator name Meaning
& Bit-wise AND
| Bit-wise OR
^ Bit-wise Exclusive OR(XOR)
<< Left Shift
>> Right Shift
- Bit-wise 1’s component
24
Bitwise Operators
 Examples:-
#include<stdio.h>
#include<conio.h>
Void main()
{
int x;
int mul,div;
clrscr();
printf(“Give one integer numbern”);
scanf(“%d”,&x);
mul = x << 1; /* left shift */
div = x >> 1; /* right shift */
printf(“multiplication of %d by 2 = %dn”,x,mul);
scanf(“division of %d by 2 = %dn”,x,div);
}
25
Bitwise Operators
 Output:-
Give one integer number
5
multiplication of 5 by 2 = 10
Division of by 2 = 2
26
Other Special Operators
 ‘C’ language provides other special operator. They
are:
Comma operator
sizeof operator
Arrow(->) operator
dot operator
* operator and & operator
27
Other Special Operators
 Comma operator:-
(,) Comma operator is used to combine multiple statements.
It is used to separate multiple expressions. It has the lowest
precedence. It is mainly used in for loop.
The expressions which are separated by comma operator
are evaluated from left to right.
For example, the following statement
z = (x=5, x+5);
is equivalent to the statement sequence
x = 5;
z = x+5;
28
Other Special Operators
 sizeof operator:-
sizeof operator is used to find our the storage requirement
of an operand in memory. It is an unary operator which
returns size in bytes.
The syntax is sizeof(operand)
For example,
sizeof(float) returns the value 4
sizeof(int) return the value 2
The statement sequence,
char c;
sizeof(c);
will return the value 1, because c is character type variable.
29
THANK YOU
30

Weitere ähnliche Inhalte

Was ist angesagt?

C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 

Was ist angesagt? (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Operators in C
Operators in COperators in C
Operators in C
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
 
Programming in ansi C by Balaguruswami
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by Balaguruswami
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
String predefined functions in C programming
String predefined functions in C  programmingString predefined functions in C  programming
String predefined functions in C programming
 
History of c
History of cHistory of c
History of c
 

Ähnlich wie Operators-computer programming and utilzation

PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
Nithya K
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 

Ähnlich wie Operators-computer programming and utilzation (20)

Theory3
Theory3Theory3
Theory3
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
 
Operators
OperatorsOperators
Operators
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 )
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 
Coper in C
Coper in CCoper in C
Coper in C
 

Mehr von Kaushal Patel

Mehr von Kaushal Patel (19)

5 amazing monuments of ancient india
5 amazing monuments of ancient india5 amazing monuments of ancient india
5 amazing monuments of ancient india
 
Simple vapour compression system
Simple vapour compression systemSimple vapour compression system
Simple vapour compression system
 
Regenerative and reduced air refrigeration system
Regenerative and reduced air refrigeration  systemRegenerative and reduced air refrigeration  system
Regenerative and reduced air refrigeration system
 
Gear manufacturing methods
Gear manufacturing methodsGear manufacturing methods
Gear manufacturing methods
 
Combustion Chamber for Compression Ignition Engines
Combustion Chamber for Compression Ignition EnginesCombustion Chamber for Compression Ignition Engines
Combustion Chamber for Compression Ignition Engines
 
Elliptical trammel
Elliptical trammelElliptical trammel
Elliptical trammel
 
Time response analysis
Time response analysisTime response analysis
Time response analysis
 
Tracing of cartesian curve
Tracing of cartesian curveTracing of cartesian curve
Tracing of cartesian curve
 
simple casestudy on building materials
simple casestudy on building materialssimple casestudy on building materials
simple casestudy on building materials
 
linear tranformation- VC&LA
linear tranformation- VC&LAlinear tranformation- VC&LA
linear tranformation- VC&LA
 
Broching machine-manufacturing process-1
Broching machine-manufacturing process-1Broching machine-manufacturing process-1
Broching machine-manufacturing process-1
 
Case study 2 storke-elements of mechanical engineering
Case study 2 storke-elements of mechanical engineeringCase study 2 storke-elements of mechanical engineering
Case study 2 storke-elements of mechanical engineering
 
Methods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematicsMethods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematics
 
Drilling machines-manufacturing process-1
Drilling machines-manufacturing process-1Drilling machines-manufacturing process-1
Drilling machines-manufacturing process-1
 
Stress and strain- mechanics of solid
Stress and strain- mechanics of solidStress and strain- mechanics of solid
Stress and strain- mechanics of solid
 
Engineering thermodynemics-difference between heat and work
Engineering thermodynemics-difference between heat and workEngineering thermodynemics-difference between heat and work
Engineering thermodynemics-difference between heat and work
 
Types of cables
Types of cablesTypes of cables
Types of cables
 
Nano science _technology
Nano science _technologyNano science _technology
Nano science _technology
 
Cochran Boiler-ELEMENTS OF MECHANICAL ENGINEERING
Cochran Boiler-ELEMENTS OF MECHANICAL ENGINEERINGCochran Boiler-ELEMENTS OF MECHANICAL ENGINEERING
Cochran Boiler-ELEMENTS OF MECHANICAL ENGINEERING
 

Kürzlich hochgeladen

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 

Kürzlich hochgeladen (20)

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 

Operators-computer programming and utilzation

  • 1. COMPUTER PROGRAMING AND UTILIZATION By Kaushal Patel TYPES OF OPERATORS
  • 2. Operators are the verbs of a language that help the user perform computations on values. “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables” Ex: a + b Definition 2
  • 3. Operators in C 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators 3
  • 4. Arithmetic operators Arithmetic operators are used to perform arithmetic operations. ‘C’ language supports following arithmetic operators. Operator example Meaning + a + b Addition –unary - a – b Subtraction- unary * a * b Multiplication / a / b Division % a % b Modulo division- remainder 4
  • 5.  The ‘C’ language does not provide the operator for exponentiation. + and – operator can be used as unary operator also. Except % operator all arithmetic can be used with any type of numeric operands, while % operator can only be used with integer data type only.  Following program will clarify how arithmetic operators behave with different data type, particularly the use of /and % operator. Arithmetic operators 5
  • 6. Example:- # include<stdio.h> main() { int x=25; int y=4; printf(“%d+%d=%dn” ,x, y, x+y); printf(“%d-%d=%dn” ,x, y, x-y); printf(“%d*%d=%dn” ,x, y, x*y); printf(“%d/%d=%dn” ,x, y, x/y); printf(“%d%%d=%dn” ,x, y, x%y); } Arithmetic operators 6
  • 8. Explanation: First three operations are obvious. The division operation gives the answer 6 because, the variables x and y are integer variables, when we use / with integer operands the result will be integer number. while,%operator produce the remainder after division of 25by 4. Arithmetic operators 8
  • 9. Assignment Operators  We have already used the assignment operator = in previous programs ‘C’ language supports = assignment operator. It is used to assign a value to a variable. The syntax is variablename = expression  The expression can be a constant, variable name or any valid expression.  ‘C’ also supports the use of shorthand notation also. form is variable = varname operator expression; into varname operator = expression; 9
  • 10. Assignment Operators  Use of shorthand notation makes your statement concise and program writing becomes faster when variable name are long in size Assignment Operator Shorthand a = a + 5; a += 5; a = a – 5; a -= 5; a = a * 5; a *= 5; a = a /5; a /= 5; a = a % 5(assuming a as integer) a %= 5; 10
  • 11. Assignment Operators  Example:- #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf(“Give the value of an”); scanf(“%d”,&a); a += 5; printf(“a= %dn”,a); a -= 5; printf (“a =%dn”,a); getch(); } 11
  • 12. Assignment Operators  Output:- Give the value of a 4 a =9 a =4 12
  • 13. Logical Operators  Sometimes in programming, we need to take certain action if some condition are true or false. Logical operators help us to combine more than one conditions, and based on the outcome certain steps are taken. Operator name Meaning && Logical AND || Logical OR ! Logical NOT(Negation) 13
  • 14. Logical Operators  Logical NOT is an unary operator. In an expression, we can use more then on logical operation. If more then one operator is used, !(NOT) is evaluated first, then &&(AND) and then ||(OR), we can use parentheses to change the order of evaluation. for example, if we have a = 2, b = 3 and c = 5 then, Expression Value Remark a <b && c ==5 True Both expression are true ! (5 >3) False 5>3 is true & negation of true is false a< b || c=10 True a<b is true which makes the expression true (b> a) && (c !=5) False c =5, s0 second condition false (b<c || b>a) && (c==5) True Both sub expression are true 14
  • 15. Increment & Decrement Operators C supports 2 useful operators namely 1. Increment (++) 2. Decrement(--)operators The (++) operator adds a value 1 to the operand The (--) operator subtracts 1 from the operand (++a) or (a++) (--a) or (a--) 15
  • 16. Examples for (++) &(--) operators:- Let the value of a =5 and b=++a then a = b =6 Let the value of a = 5 and b=a++ then a =5 but b=6 i.e.: 1. a prefix operator first adds 1 to the operand and then the result is assigned to the variable on the left ex:- (++a)or (--a) is called prefix increment or decrement 2. a postfix operator first assigns the value to the variable on left and then increments the operand. ex:- (a++)or (a--) is called postfix increment or decrement Increment & Decrement Operators 16
  • 17. If the ++ or – operator is used in an expression or assignment then prefix notation give different values. Ones should use prefix notation carefully in an assignment or expression involving other variables. Increment & Decrement Operators 17
  • 18. Example:- #include <stdio.h> #include <conio.h> main() { int x=10; int y; int z=0; clrscr(); x++; ++x; y=++x; printf(“ Value of x=%d y=%d and z-%dn”, x,y,z); z=y--; printf(“ Value of x=%d y=%d and z-%dn”, x,y,z); } Increment & Decrement Operators 18
  • 19. Output:- Value of x=13 y=13 and z=0 Value of x=13 y=12 and z=13 Increment & Decrement Operators 19
  • 20. C language has two useful operators called increment(++) and decrement (--) that operate on integer data only. The increment (++) operator increments the operand by 1, while the decrement operator (--) decrements the operand by 1, for example ,: int i , j; i = 10; j = i++ ; printf(“ %d %d “, i, j); OUTPUT:- 11 10 . First i is assigned to j and then i is incremented by 1 Increment & Decrement Operators 20
  • 21. If we have : int i, j ; I = 20; j = ++i; printf(“%d %d”, i, j); OUTPUT : first i is incremented by 1 and then assignment take place i.e., pre- increment of i. now, consider the example for (--) operator : int a, b; a=10; b= a--; printf(“%d %d”, a , b) OUTPUT : first a is assigned to b then a is decremented by 1. i.e.,post decrement takes place Increment & Decrement Operators 21
  • 22. Decrement Operator:- If we have : int i, j ; I = 20; j = --i; printf(“%d %d”, i, j); OUTPUT : 19 19. first i is decremented by 1 and then assignment take place i.e., pre-decrement of i. Note : on some compilers a space is required on both sides of ++I or i++ , i-- or --i Increment & Decrement Operators 22
  • 23. Bitwise Operators  We know that internally, the data is represented in bits 0 and 1. ‘C’ language supports some operators which can perform at the bit level. These type of operations are normally done in assembly or machine level programming. But, ‘C’ language supports bit level manipulation also, that is why ‘C’ language is also known as middle-level programming language. 23
  • 24. Bitwise Operators  Following table shows bit-wise operators with their meaning: Operator name Meaning & Bit-wise AND | Bit-wise OR ^ Bit-wise Exclusive OR(XOR) << Left Shift >> Right Shift - Bit-wise 1’s component 24
  • 25. Bitwise Operators  Examples:- #include<stdio.h> #include<conio.h> Void main() { int x; int mul,div; clrscr(); printf(“Give one integer numbern”); scanf(“%d”,&x); mul = x << 1; /* left shift */ div = x >> 1; /* right shift */ printf(“multiplication of %d by 2 = %dn”,x,mul); scanf(“division of %d by 2 = %dn”,x,div); } 25
  • 26. Bitwise Operators  Output:- Give one integer number 5 multiplication of 5 by 2 = 10 Division of by 2 = 2 26
  • 27. Other Special Operators  ‘C’ language provides other special operator. They are: Comma operator sizeof operator Arrow(->) operator dot operator * operator and & operator 27
  • 28. Other Special Operators  Comma operator:- (,) Comma operator is used to combine multiple statements. It is used to separate multiple expressions. It has the lowest precedence. It is mainly used in for loop. The expressions which are separated by comma operator are evaluated from left to right. For example, the following statement z = (x=5, x+5); is equivalent to the statement sequence x = 5; z = x+5; 28
  • 29. Other Special Operators  sizeof operator:- sizeof operator is used to find our the storage requirement of an operand in memory. It is an unary operator which returns size in bytes. The syntax is sizeof(operand) For example, sizeof(float) returns the value 4 sizeof(int) return the value 2 The statement sequence, char c; sizeof(c); will return the value 1, because c is character type variable. 29