尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
ELEMENTS OF PROGRAM
STATEMENTS
OPERATORS
PRECEDENCE & ASSOCIATIVITY
Expression and Operators
Compiled By: Kamal Acharya
Elements of a program
 Literals  fixed data written into a program
 Variables & constants  placeholders (in memory)
for pieces of data
 Types  sets of possible values for data
 Expressions  combinations of operands (such as
variables or even "smaller" expressions) and
operators. They compute new values from old ones.
 Assignments  used to store values into variables
 Statements  "instructions". In C, any expression
followed by a semicolon is a statement
Compiled By: Kamal Acharya
Elements of a program
 Control-flow constructs  constructs that allow
statements or groups of statements to be executed
only when certain conditions hold or to be
executed more than once.
 Functions  named blocks of statements that
perform a well-defined operation.
 Libraries  collections of functions.
Compiled By: Kamal Acharya
Statement
 Statements are elements in a program which
(usually) ended up with semi-colon (;)
 e.g. below is a variables declaration statement
int a, b, c;
• Preprocessor directives (i.e. #include and define)
are not statements. They don’t use semi-colon
Compiled By: Kamal Acharya
An expression statement is a statement that results a value
Some examples of expression Value
• Literal expression
e.g. 2, “A+”, ‘B’
The literal itself
• Variable expression
e.g. Variable1
• arithmetic expression
e.g. 2 + 3 -1
The content of the variable
The result of the operation
Compiled By: Kamal Acharya
Operators
 Operators can be classified according to
 the type of their operands and of their output
 Arithmetic
 Relational
 Logical
 Bitwise
 the number of their operands
 Unary (one operand)
 Binary (two operands)
Compiled By: Kamal Acharya
Binary expression
Compiled By: Kamal Acharya
Unary Expression
Compiled By: Kamal Acharya
Ternary Expression
(a>2) ? 1: 0
Operator
First operand
is a condition
Second operand
is a value
Third operand
is another value
Compiled By: Kamal Acharya
Arithmetic operators
 They operate on numbers and the result is a
number.
 The type of the result depends on the types of the
operands.
 If the types of the operands differ (e.g. an integer
added to a floating point number), one is
"promoted" to other.
 The "smaller" type is promoted to the "larger" one.
char  int  float  double
Compiled By: Kamal Acharya
Example of promotion:
The result of the following “double division” is 2.5
5 / 2.0
Before the division process, 5 is promoted from integer 5
to float 5.0
The result of the following “integer division” is 2
5 / 2
There is no promotion occurred. Both operands are the
same type.
Compiled By: Kamal Acharya
Arithmetic operators: +, *
 + is the addition operator
 * is the multiplication operator
 They are both binary
Compiled By: Kamal Acharya
Arithmetic operator: 
 This operator has two meanings:
 subtraction operator (binary)
 negation operator (unary)
e.g. 31 - 2
e.g. -10
Compiled By: Kamal Acharya
Arithmetic operator: /
 The result of integer division is an integer:
e.g. 5 / 2 is 2, not 2.5
Compiled By: Kamal Acharya
Arithmetic operator: %
 The modulus (remainder) operator.
 It computes the remainder after the first operand
is divided by the second
 It is useful for making cycles of numbers:
 For an int variable x :
if x is: 0 1 2 3 4 5 6 7 8 9 ...
(x%4) is: 0 1 2 3 0 1 2 3 0 1 ...
e.g. 5 % 2 is 1, 6 % 2 is 0
Compiled By: Kamal Acharya
Compiled By: Kamal Acharya
Compiled By: Kamal Acharya
Relational operators
 These perform comparisons and the result is what is
called a boolean: a value TRUE or FALSE
 FALSE is represented by 0; anything else is TRUE
 The relational operators are:
 < (less than)
 <= (less than or equal to)
 > (greater than)
 >= (greater than or equal to)
 == (equal to)
 != (not equal to)
Compiled By: Kamal Acharya
Compiled By: Kamal Acharya
Logical operators
(also called Boolean operators)
 These have Boolean operands and the result is also
a Boolean.
 The basic Boolean operators are:
 && (logical AND)
 || (logical OR)
 ! (logical NOT) -- unary
Compiled By: Kamal Acharya
Compiled By: Kamal Acharya
Assignment operator: =
 Binary operator used to assign a value to a variable.
Compiled By: Kamal Acharya
Special assignment operators
 write a += b; instead of a = a + b;
 write a -= b; instead of a = a - b;
 write a *= b; instead of a = a * b;
 write a /= b; instead of a = a / b;
 write a %= b; instead of a = a % b;
Compiled By: Kamal Acharya
Special assignment operators
 Increment, decrement operators: ++, --
 Instead of a = a + 1 you can write a++ or ++a
 Instead of a = a - 1 you can write a-- or --a
 What is the difference?
num = 10;
ans = num++;
num = 10;
ans = ++num;
First increment num,
then assign num to ans.
In the end,
num is 11
ans is 11
First assign num to ans,
then increment num.
In the end,
num is 11
ans is 10
post-increment pre-increment
Compiled By: Kamal Acharya
Result of postfix Increment
Compiled By: Kamal Acharya
Result of Prefix Increment
Compiled By: Kamal Acharya
Precedence & associativity
 How would you evaluate the expression
17 - 8 * 2 ?
Is it 17 - (8 * 2)
or (17 - 8) * 2 ?
 These two forms give different results.
 We need rules!
Compiled By: Kamal Acharya
Precedence & associativity
 When two operators compete for the same operand
(e.g. in 17 - 8 * 2 the operators - and * compete for
8) the rules of precedence specify which operator
wins.
 The operator with the higher precedence wins
 If both competing operators have the same
precedence, then the rules of associativity
determine the winner.
Compiled By: Kamal Acharya
Precedence & associativity
! Unary –
* / %
+ –
< <= >= >
= = !=
&&
||
=
higher precedence
lower precedence
Associativity: execute left-to-right (except
for = and unary – )
Compiled By: Kamal Acharya
Example: Left associativity
3 * 8 / 4 % 4 * 5
Compiled By: Kamal Acharya
Example: Right associativity
a += b *= c-=5
Compiled By: Kamal Acharya
Precedence & associativity
 Examples:
X =17 - 2 * 8 Ans: X=17-(2*8) , X=1
Y = 17 - 2 - 8 Ans: Y = (17-2)-8, Y=7
Z = 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 *2 + 1 ?
Not sure? Confused? then use parentheses in your code!
Compiled By: Kamal Acharya
Sizeof() Operator
 C provides a unary operator named sizeof to find
number of bytes needed to store an object.
 An expression of the form sizeof(object) returns an
integer value that represents the number of bytes
needed to store that object in memory.
 printf(“%d”,sizeof(int)); /* prints 2 */
printf(“%d”,sizeof(char)); /* prints 1 */
printf(“%d”,sizeof(float)); /* prints 4 */
Compiled By: Kamal Acharya

More Related Content

What's hot

Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
Operators in java
Operators in javaOperators in java
Operators in java
Muthukumaran Subramanian
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Templates
TemplatesTemplates
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
The Loops
The LoopsThe Loops
The Loops
Krishma Parekh
 
structured programming
structured programmingstructured programming
structured programming
Ahmad54321
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 

What's hot (20)

Operators in java
Operators in javaOperators in java
Operators in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Loops c++
Loops c++Loops c++
Loops c++
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Data types in C
Data types in CData types in C
Data types in C
 
Templates
TemplatesTemplates
Templates
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Structure in C
Structure in CStructure in C
Structure in C
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Array in c
Array in cArray in c
Array in c
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
The Loops
The LoopsThe Loops
The Loops
 
structured programming
structured programmingstructured programming
structured programming
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 

Similar to Expression and Operartor In C Programming

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
C# operators
C# operatorsC# operators
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
YuvarajuCherukuri
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
jahanullah
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
guest58c84c
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
sanya6900
 
Operators
OperatorsOperators
Operators
Kamran
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
Dr.Sandhiya Ravi
 
Operators in c by anupam
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
CGC Technical campus,Mohali
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
Swarup Boro
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Kathirvel Ayyaswamy
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
Fiaz Khokhar
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
divyalakshmi77
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
MuhammadAtif231
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
Prof Ansari
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
Emmanuel Alimpolos
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
Emmanuel Alimpolos
 
Coper in C
Coper in CCoper in C
Coper in C
thirumalaikumar3
 

Similar to Expression and Operartor In C Programming (20)

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
C# operators
C# operatorsC# operators
C# operators
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Operators
OperatorsOperators
Operators
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Operators in c by anupam
Operators in c by anupamOperators in c by anupam
Operators in c by anupam
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Coper in C
Coper in CCoper in C
Coper in C
 

More from Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
Kamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
Kamal Acharya
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
Kamal Acharya
 
Functions in php
Functions in phpFunctions in php
Functions in php
Kamal Acharya
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
Kamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
Kamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
Kamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
Kamal Acharya
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
Kamal Acharya
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
Kamal Acharya
 
Search Engines
Search EnginesSearch Engines
Search Engines
Kamal Acharya
 
Web Mining
Web MiningWeb Mining
Web Mining
Kamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
Kamal Acharya
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
Kamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
Kamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
Kamal Acharya
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
Kamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
Kamal Acharya
 

More from Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Recently uploaded

Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
Ben Aldrich
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
MattVassar1
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Catherine Dela Cruz
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
Talking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual AidsTalking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual Aids
MattVassar1
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
Infosec
 
Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024
Friends of African Village Libraries
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
Nguyen Thanh Tu Collection
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
Celine George
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
khabri85
 
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT KanpurDiversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
Creativity for Innovation and Speechmaking
Creativity for Innovation and SpeechmakingCreativity for Innovation and Speechmaking
Creativity for Innovation and Speechmaking
MattVassar1
 
nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...
chaudharyreet2244
 
Slides Peluncuran Amalan Pemakanan Sihat.pptx
Slides Peluncuran Amalan Pemakanan Sihat.pptxSlides Peluncuran Amalan Pemakanan Sihat.pptx
Slides Peluncuran Amalan Pemakanan Sihat.pptx
shabeluno
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
RuchiRathor2
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 

Recently uploaded (20)

Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
 
Talking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual AidsTalking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual Aids
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
 
Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
 
Diversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT KanpurDiversity Quiz Finals by Quiz Club, IIT Kanpur
Diversity Quiz Finals by Quiz Club, IIT Kanpur
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
Creativity for Innovation and Speechmaking
Creativity for Innovation and SpeechmakingCreativity for Innovation and Speechmaking
Creativity for Innovation and Speechmaking
 
nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...nutrition in plants chapter 1 class 7...
nutrition in plants chapter 1 class 7...
 
Slides Peluncuran Amalan Pemakanan Sihat.pptx
Slides Peluncuran Amalan Pemakanan Sihat.pptxSlides Peluncuran Amalan Pemakanan Sihat.pptx
Slides Peluncuran Amalan Pemakanan Sihat.pptx
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 

Expression and Operartor In C Programming

  • 1. ELEMENTS OF PROGRAM STATEMENTS OPERATORS PRECEDENCE & ASSOCIATIVITY Expression and Operators Compiled By: Kamal Acharya
  • 2. Elements of a program  Literals  fixed data written into a program  Variables & constants  placeholders (in memory) for pieces of data  Types  sets of possible values for data  Expressions  combinations of operands (such as variables or even "smaller" expressions) and operators. They compute new values from old ones.  Assignments  used to store values into variables  Statements  "instructions". In C, any expression followed by a semicolon is a statement Compiled By: Kamal Acharya
  • 3. Elements of a program  Control-flow constructs  constructs that allow statements or groups of statements to be executed only when certain conditions hold or to be executed more than once.  Functions  named blocks of statements that perform a well-defined operation.  Libraries  collections of functions. Compiled By: Kamal Acharya
  • 4. Statement  Statements are elements in a program which (usually) ended up with semi-colon (;)  e.g. below is a variables declaration statement int a, b, c; • Preprocessor directives (i.e. #include and define) are not statements. They don’t use semi-colon Compiled By: Kamal Acharya
  • 5. An expression statement is a statement that results a value Some examples of expression Value • Literal expression e.g. 2, “A+”, ‘B’ The literal itself • Variable expression e.g. Variable1 • arithmetic expression e.g. 2 + 3 -1 The content of the variable The result of the operation Compiled By: Kamal Acharya
  • 6. Operators  Operators can be classified according to  the type of their operands and of their output  Arithmetic  Relational  Logical  Bitwise  the number of their operands  Unary (one operand)  Binary (two operands) Compiled By: Kamal Acharya
  • 9. Ternary Expression (a>2) ? 1: 0 Operator First operand is a condition Second operand is a value Third operand is another value Compiled By: Kamal Acharya
  • 10. Arithmetic operators  They operate on numbers and the result is a number.  The type of the result depends on the types of the operands.  If the types of the operands differ (e.g. an integer added to a floating point number), one is "promoted" to other.  The "smaller" type is promoted to the "larger" one. char  int  float  double Compiled By: Kamal Acharya
  • 11. Example of promotion: The result of the following “double division” is 2.5 5 / 2.0 Before the division process, 5 is promoted from integer 5 to float 5.0 The result of the following “integer division” is 2 5 / 2 There is no promotion occurred. Both operands are the same type. Compiled By: Kamal Acharya
  • 12. Arithmetic operators: +, *  + is the addition operator  * is the multiplication operator  They are both binary Compiled By: Kamal Acharya
  • 13. Arithmetic operator:   This operator has two meanings:  subtraction operator (binary)  negation operator (unary) e.g. 31 - 2 e.g. -10 Compiled By: Kamal Acharya
  • 14. Arithmetic operator: /  The result of integer division is an integer: e.g. 5 / 2 is 2, not 2.5 Compiled By: Kamal Acharya
  • 15. Arithmetic operator: %  The modulus (remainder) operator.  It computes the remainder after the first operand is divided by the second  It is useful for making cycles of numbers:  For an int variable x : if x is: 0 1 2 3 4 5 6 7 8 9 ... (x%4) is: 0 1 2 3 0 1 2 3 0 1 ... e.g. 5 % 2 is 1, 6 % 2 is 0 Compiled By: Kamal Acharya
  • 18. Relational operators  These perform comparisons and the result is what is called a boolean: a value TRUE or FALSE  FALSE is represented by 0; anything else is TRUE  The relational operators are:  < (less than)  <= (less than or equal to)  > (greater than)  >= (greater than or equal to)  == (equal to)  != (not equal to) Compiled By: Kamal Acharya
  • 20. Logical operators (also called Boolean operators)  These have Boolean operands and the result is also a Boolean.  The basic Boolean operators are:  && (logical AND)  || (logical OR)  ! (logical NOT) -- unary Compiled By: Kamal Acharya
  • 22. Assignment operator: =  Binary operator used to assign a value to a variable. Compiled By: Kamal Acharya
  • 23. Special assignment operators  write a += b; instead of a = a + b;  write a -= b; instead of a = a - b;  write a *= b; instead of a = a * b;  write a /= b; instead of a = a / b;  write a %= b; instead of a = a % b; Compiled By: Kamal Acharya
  • 24. Special assignment operators  Increment, decrement operators: ++, --  Instead of a = a + 1 you can write a++ or ++a  Instead of a = a - 1 you can write a-- or --a  What is the difference? num = 10; ans = num++; num = 10; ans = ++num; First increment num, then assign num to ans. In the end, num is 11 ans is 11 First assign num to ans, then increment num. In the end, num is 11 ans is 10 post-increment pre-increment Compiled By: Kamal Acharya
  • 25. Result of postfix Increment Compiled By: Kamal Acharya
  • 26. Result of Prefix Increment Compiled By: Kamal Acharya
  • 27. Precedence & associativity  How would you evaluate the expression 17 - 8 * 2 ? Is it 17 - (8 * 2) or (17 - 8) * 2 ?  These two forms give different results.  We need rules! Compiled By: Kamal Acharya
  • 28. Precedence & associativity  When two operators compete for the same operand (e.g. in 17 - 8 * 2 the operators - and * compete for 8) the rules of precedence specify which operator wins.  The operator with the higher precedence wins  If both competing operators have the same precedence, then the rules of associativity determine the winner. Compiled By: Kamal Acharya
  • 29. Precedence & associativity ! Unary – * / % + – < <= >= > = = != && || = higher precedence lower precedence Associativity: execute left-to-right (except for = and unary – ) Compiled By: Kamal Acharya
  • 30. Example: Left associativity 3 * 8 / 4 % 4 * 5 Compiled By: Kamal Acharya
  • 31. Example: Right associativity a += b *= c-=5 Compiled By: Kamal Acharya
  • 32. Precedence & associativity  Examples: X =17 - 2 * 8 Ans: X=17-(2*8) , X=1 Y = 17 - 2 - 8 Ans: Y = (17-2)-8, Y=7 Z = 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 *2 + 1 ? Not sure? Confused? then use parentheses in your code! Compiled By: Kamal Acharya
  • 33. Sizeof() Operator  C provides a unary operator named sizeof to find number of bytes needed to store an object.  An expression of the form sizeof(object) returns an integer value that represents the number of bytes needed to store that object in memory.  printf(“%d”,sizeof(int)); /* prints 2 */ printf(“%d”,sizeof(char)); /* prints 1 */ printf(“%d”,sizeof(float)); /* prints 4 */ Compiled By: Kamal Acharya
  翻译: