SlideShare a Scribd company logo
Operators and Expressions
Topics
• Operators and classification
• Expression
• Operator precedence and associativity
• Type conversion
Operators
• Operator: An operator is a symbol that tells the
computer to perform specific mathematical or logical
manipulation.
• Categories of C operators:
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
Arithmetic Operator
– Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division
Relational Operators
– Operator Meaning
< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to
== is equal to
!= is not equal to
Logical Operators
– Operator Meaning
&& logical AND
|| logical OR
! Logical NOT
Op-1 Op-2 Op-1&&Op-2 Op-1||Op-2
0 0 0 0
0 Non-zero 0 1
Non zero 0 0 1
Non zero Non zero 1 1
Assignment Operators
• Assignment operator ‘=‘ is used to assign the
result of an expression to a variable.
• ‘=‘ also can be used in shorthand assignment
operator.
• Ex: x = x + y can be written as x +=y
Increment and Decrement Operators
• Increment operator: ++
• Decrement operator: --
• ++ adds 1 to the operand and -- subtracts 1 from the
operand.
• Difference between x++ and ++x: x++ is post increment
and in case of assignment, the value first assigned and
then increment operand by 1. ++x is pre-increment and
first value of x is incremented by 1 and then the value is
assigned.
if x = 10 and y = x++ then after execution
value of x = 11 and y = 10
similarly, if x=10 and y=++x then after execution value
of x=y=11
• Difference between x-- and --x
Conditional Operator
• The pair ? : is known as conditional operator
• Rule: var = (condition)?exp1:exp2;
• If the condition is true then value of var = exp1
else var = exp2
• Ex: If x = 10, y = 20 and z = (x+10<y)? x*y: y/x ,
the value of z after execution will be 2
Bitwise and Special Operators
• Bitwise operators: &, |, <<, >>, ~
• Special operators: , ;
Arithmetic Expression
• An arithmetic expression is a combination of
variables, constants and operators arranged as
per the syntax of the language.
• Expression are evaluated using an assignment
statement of the form
variable = expression;
• Ex: x = a*b-10;
y = b+c*a;
Operator precedence and Associativity
• Precedence: It is the process of assigning
priority to the operators in the expression.
• High priority: * / %
• Low priority: + -
• Associativity: Operators of the same precedence
are evaluated either from left to right or from
right to left, depending on the level. This is know
as associativity.
• Ex: 5+6-3
Type conversion in Expression
• Consider 7/2 = 3 but if you need the result like
7/2= 3.5 then what you will do???
• The process of converting type of any
expression is called casting.
• The general form: (type_name) expression
• Ex: (float) 7/2 = 3.5

More Related Content

DOC
Week2 dq4
amaxwell2012
 
PPT
Chapter 04
Graham Royce
 
PDF
SPL 6 | Operators in C
Mohammad Imam Hossain
 
PPTX
COM1407: C Operators
Hemantha Kulathilake
 
PPT
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
PPTX
Operators in java
yugandhar vadlamudi
 
PPTX
Operator Precedence and Associativity
Nicole Ynne Estabillo
 
PPTX
Operators and expressions
vishaljot_kaur
 
Week2 dq4
amaxwell2012
 
Chapter 04
Graham Royce
 
SPL 6 | Operators in C
Mohammad Imam Hossain
 
COM1407: C Operators
Hemantha Kulathilake
 
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
Operators in java
yugandhar vadlamudi
 
Operator Precedence and Associativity
Nicole Ynne Estabillo
 
Operators and expressions
vishaljot_kaur
 

What's hot (18)

PPTX
Road to code
Apoorvi Kapoor
 
PPTX
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
PPT
C Prog. - Operators and Expressions
vinay arora
 
PDF
itft-Operators in java
Atul Sehdev
 
PPT
Java 2
Preethi Nambiar
 
PPT
Operators
Devi Pradeep Podugu
 
PDF
Operators in c programming
savitamhaske
 
PPTX
Type Conversion, Precedence and Associativity
Aakash Singh
 
PPTX
Python ppt
GoogleDeveloperStude2
 
PPTX
Operator
VIKASH SAMRAT
 
PPTX
Logical and Conditional Operator In C language
Abdul Rehman
 
DOCX
C – operators and expressions
Chukka Nikhil Chakravarthy
 
PPTX
Relational operators
Graphic Era Hill University,Bhimtal
 
PPTX
Type conversion, precedence, associativity in c programming
Dhrumil Panchal
 
PPTX
L3 operators
teach4uin
 
PDF
Operators in java
Ravi_Kant_Sahu
 
PPTX
Operators in java
Madishetty Prathibha
 
PDF
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Road to code
Apoorvi Kapoor
 
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
C Prog. - Operators and Expressions
vinay arora
 
itft-Operators in java
Atul Sehdev
 
Operators in c programming
savitamhaske
 
Type Conversion, Precedence and Associativity
Aakash Singh
 
Operator
VIKASH SAMRAT
 
Logical and Conditional Operator In C language
Abdul Rehman
 
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Type conversion, precedence, associativity in c programming
Dhrumil Panchal
 
L3 operators
teach4uin
 
Operators in java
Ravi_Kant_Sahu
 
Operators in java
Madishetty Prathibha
 
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Ad

Similar to Chap 3(operator expression) (20)

PPTX
Operators and Expressions
Munazza-Mah-Jabeen
 
PPTX
L3 operators
teach4uin
 
PPTX
L3 operators
teach4uin
 
PPT
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
PDF
introduction to c programming - Topic 3.pdf
rajd20284
 
PPTX
java-tokens-data-types.pptx ciiiidddidifif
sayedshaad02
 
PPTX
OCA JAVA - 3 Programming with Java Operators
Fernando Gil
 
PDF
Types of Operators in C
Thesis Scientist Private Limited
 
PPT
9 cm604.10
myrajendra
 
PPTX
operat in vb .pptx
classall
 
PPTX
lecture4 pgdca.pptx
classall
 
PPTX
Operators in java script
Abhinav Somani
 
PDF
Coper in C
thirumalaikumar3
 
PPTX
OPERATORS OF C++
ANANT VYAS
 
PPTX
Csc240 -lecture_5
Ainuddin Yousufzai
 
PDF
C++ Tokens
Amrit Kaur
 
PPTX
Operators in Python
Anusuya123
 
PPT
Operation and expression in c++
Online
 
PPT
Expressions in c++
zeeshan turi
 
PPTX
c programming2.pptx
YuvarajuCherukuri
 
Operators and Expressions
Munazza-Mah-Jabeen
 
L3 operators
teach4uin
 
L3 operators
teach4uin
 
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
introduction to c programming - Topic 3.pdf
rajd20284
 
java-tokens-data-types.pptx ciiiidddidifif
sayedshaad02
 
OCA JAVA - 3 Programming with Java Operators
Fernando Gil
 
Types of Operators in C
Thesis Scientist Private Limited
 
9 cm604.10
myrajendra
 
operat in vb .pptx
classall
 
lecture4 pgdca.pptx
classall
 
Operators in java script
Abhinav Somani
 
Coper in C
thirumalaikumar3
 
OPERATORS OF C++
ANANT VYAS
 
Csc240 -lecture_5
Ainuddin Yousufzai
 
C++ Tokens
Amrit Kaur
 
Operators in Python
Anusuya123
 
Operation and expression in c++
Online
 
Expressions in c++
zeeshan turi
 
c programming2.pptx
YuvarajuCherukuri
 
Ad

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Recently uploaded (20)

PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
CDH. pptx
AneetaSharma15
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 

Chap 3(operator expression)

  • 1. Operators and Expressions Topics • Operators and classification • Expression • Operator precedence and associativity • Type conversion
  • 2. Operators • Operator: An operator is a symbol that tells the computer to perform specific mathematical or logical manipulation. • Categories of C operators: 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 Operator – Operator Meaning + Addition - Subtraction * Multiplication / Division % Modulo division
  • 4. Relational Operators – Operator Meaning < is less than <= is less than or equal to > is greater than >= is greater than or equal to == is equal to != is not equal to
  • 5. Logical Operators – Operator Meaning && logical AND || logical OR ! Logical NOT Op-1 Op-2 Op-1&&Op-2 Op-1||Op-2 0 0 0 0 0 Non-zero 0 1 Non zero 0 0 1 Non zero Non zero 1 1
  • 6. Assignment Operators • Assignment operator ‘=‘ is used to assign the result of an expression to a variable. • ‘=‘ also can be used in shorthand assignment operator. • Ex: x = x + y can be written as x +=y
  • 7. Increment and Decrement Operators • Increment operator: ++ • Decrement operator: -- • ++ adds 1 to the operand and -- subtracts 1 from the operand. • Difference between x++ and ++x: x++ is post increment and in case of assignment, the value first assigned and then increment operand by 1. ++x is pre-increment and first value of x is incremented by 1 and then the value is assigned. if x = 10 and y = x++ then after execution value of x = 11 and y = 10 similarly, if x=10 and y=++x then after execution value of x=y=11 • Difference between x-- and --x
  • 8. Conditional Operator • The pair ? : is known as conditional operator • Rule: var = (condition)?exp1:exp2; • If the condition is true then value of var = exp1 else var = exp2 • Ex: If x = 10, y = 20 and z = (x+10<y)? x*y: y/x , the value of z after execution will be 2
  • 9. Bitwise and Special Operators • Bitwise operators: &, |, <<, >>, ~ • Special operators: , ;
  • 10. Arithmetic Expression • An arithmetic expression is a combination of variables, constants and operators arranged as per the syntax of the language. • Expression are evaluated using an assignment statement of the form variable = expression; • Ex: x = a*b-10; y = b+c*a;
  • 11. Operator precedence and Associativity • Precedence: It is the process of assigning priority to the operators in the expression. • High priority: * / % • Low priority: + - • Associativity: Operators of the same precedence are evaluated either from left to right or from right to left, depending on the level. This is know as associativity. • Ex: 5+6-3
  • 12. Type conversion in Expression • Consider 7/2 = 3 but if you need the result like 7/2= 3.5 then what you will do??? • The process of converting type of any expression is called casting. • The general form: (type_name) expression • Ex: (float) 7/2 = 3.5