SlideShare a Scribd company logo
Type Conversion
Precedence & Associativity
- Aakash Singh
C
Learners
Type Conversion
 What is Type Conversion?
• Type Casting or Type Conversion is a way to
convert a variable from one data type to another
data type.
• For example, if you want to store a long value
into a simple integer then you can type cast long
to int.
2
Type Conversion
 Types of Type Conversion
• There are two types of type conversion –
1. Implicit Type Conversion
2. Explicit Type Conversion
3
1. Implicit Type Conversion
 What is Implicit Type Conversion?
• C automatically converts any intermediate values
to the proper type so that the expression can be
evaluated without losing any significance.
• This automatic conversion is known implicit type
conversion.
• If the operands are of different types, the ‘lower
type’ is automatically converted to the ‘higher’
type before the operation proceeds.
• The result is of the higher type.
4
Implicit Type Conversion
short char
int
Unsigned int
long int
Unsigned long int
float
double
long double
Conversion
Hierarchy
C uses rule that, in all expressions except assignments, any implicit type
conversions are made from a lower size to a higher size type as shown
below.
This hierarchy
can be used
while evaluating
expressions.
5
Example of Implicit Type Conversion
6
Example of Implicit Type Conversion
7
1. Explicit Type Conversion
 What is Explicit Type Conversion?
• The type conversion performed by the
programmer by posing the data type of the
expression of specific type is known as explicit
type conversion.
• The general form of a cast is :
(type-name) expression
• Here, ‘type-name’ is one of the standard C data
types and the expression may be a constant,
variable, or an expression.
8
Use of Explicit Type Casting
9
Example Action
X=(int)7.5
7.5 is converted to integer by
truncation.
a = (int)21.3/(int)4.5
Evaluated as (21/4) and the result
would be 5.
b = (double)sum/n Division is done in floating point mode.
y = (int)(a+b)
The result of (a+b) is converted to
integer.
z = (int)a+b
a is converted to integer and then
added to b.
p = cos((double)x) Converts x to double before using it.
Example of Explicit Type Conversion
10
Example of Explicit Type Conversion
11
Precedence & Associativity
 What is Precedence?
• C has a precedence associated with it. This
precedence is used to determine how an expression
involving more than one operator is evaluated.
 What is Associativity?
• The operators at higher level of precedence are
evaluated first.
• The operators of the same precedence are evaluated
either from ‘left to right’ or from ‘right to left’
depending on the level. This is known as the
associativity property of an operator.
12
Precedence & Associativity
13
 Precedence rules decides the order in which
different operators are applied.
 Associativity rule decides the order in which
multiple occurrences of the same level operator
are applied.
 C Operators with their Precedence & Associativity
are listed in the following table.
14
Operator Description Associativity Rank
()
[]
Function call
Array element
reference
Left to right 1
+
-
++
--
!
~
*
&
sizeof
(type)
Unary plus
Unary minus
Increment
Decrement
Logical Negation
Ones complement
Pointer reference
Address
Size of an object
Type cast
Right to left 2
*
/
%
Multiplication
Division
Modulus
Left to right 3
+
-
Addition
Subtraction
Left to right 4
<<
>>
Left shift
Right shift
Left to right 5
15
Operator Description Associativity Rank
<
<=
>
>=
Less than
Less than or equal to
Greater than
Greater than or equal
to
Left to right 6
==
!=
Equality
Inequality
Left to right 7
& Bitwise AND Left to right 8
^ Bitwise XOR Left to right 9
| Bitwise OR Left to right 10
&& Logical AND Left to right 11
|| Logical OR Left to right 12
?: Conditional expression Right to left 13
16
Operator Description Associativity Rank
=
*= /= %=
+= -= &=
^= |=
<<= >>=
Assignment
operators
Right to left 14
, Comma operator Left to right 15
Summary of operator precedence
17
 ‘Comma’ operator has lowest precedence.
 ‘Unary Operators’ are operators having highest
precedence.
 Operators sharing common block in the above
table have equal priority or precedence.
 While solving expression, equal priority operators
are handled on the basis of FIFO [First in First Out]
i.e., Operator Coming First is handled First.
Example of Precedence
18
Example of Associativity
19
20
Please give your precious feedbacks and suggestions at
aakashsingh07041997@gmail.com

More Related Content

What's hot

Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
HalaiHansaika
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
Md. Afif Al Mamun
 

What's hot (20)

Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Data types in java
Data types in javaData types in java
Data types in java
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
String functions in C
String functions in CString functions in C
String functions in C
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Inline function
Inline functionInline function
Inline function
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Strings in C
Strings in CStrings in C
Strings in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 

Viewers also liked

Good bye party for miss pushpa
Good  bye  party  for  miss  pushpaGood  bye  party  for  miss  pushpa
Good bye party for miss pushpa
Soham Dhameliya
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
cs submission ppt on "Goodbye party for Miss Pushpa T.S."
cs submission ppt on "Goodbye party for Miss Pushpa T.S."  cs submission ppt on "Goodbye party for Miss Pushpa T.S."
cs submission ppt on "Goodbye party for Miss Pushpa T.S." shreya sanghvi
 
Goodbye Party For Miss Pushpa T.S - Nissim Ezekiel
Goodbye Party For Miss Pushpa T.S - Nissim  EzekielGoodbye Party For Miss Pushpa T.S - Nissim  Ezekiel
Goodbye Party For Miss Pushpa T.S - Nissim Ezekiel
Shranti Hake
 
Good Bye Party For Miss Pushpa T.
Good Bye Party For Miss Pushpa T.Good Bye Party For Miss Pushpa T.
Good Bye Party For Miss Pushpa T.
Manthan070199
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
elliehood
 

Viewers also liked (9)

File Management
File ManagementFile Management
File Management
 
Good bye party for miss pushpa
Good  bye  party  for  miss  pushpaGood  bye  party  for  miss  pushpa
Good bye party for miss pushpa
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
cs submission ppt on "Goodbye party for Miss Pushpa T.S."
cs submission ppt on "Goodbye party for Miss Pushpa T.S."  cs submission ppt on "Goodbye party for Miss Pushpa T.S."
cs submission ppt on "Goodbye party for Miss Pushpa T.S."
 
Goodbye Party For Miss Pushpa T.S - Nissim Ezekiel
Goodbye Party For Miss Pushpa T.S - Nissim  EzekielGoodbye Party For Miss Pushpa T.S - Nissim  Ezekiel
Goodbye Party For Miss Pushpa T.S - Nissim Ezekiel
 
Good Bye Party For Miss Pushpa T.
Good Bye Party For Miss Pushpa T.Good Bye Party For Miss Pushpa T.
Good Bye Party For Miss Pushpa T.
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Production Function
Production FunctionProduction Function
Production Function
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 

Similar to Type Conversion, Precedence and Associativity

Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
Dhrumil Panchal
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
trupti1976
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
Ralph Weber
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
Digvijaysinh Gohil
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
LEOFAKE
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
Mohammad Imam Hossain
 
Chapter 13.1.2
Chapter 13.1.2Chapter 13.1.2
Chapter 13.1.2patcha535
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
CPU
CPUCPU
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
C++ Tokens
C++ TokensC++ Tokens
C++ Tokens
Amrit Kaur
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
shashikant pabari
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
ANANT VYAS
 

Similar to Type Conversion, Precedence and Associativity (20)

Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Chapter 13.1.2
Chapter 13.1.2Chapter 13.1.2
Chapter 13.1.2
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
CPU
CPUCPU
CPU
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
C++ Tokens
C++ TokensC++ Tokens
C++ Tokens
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
2 1 expressions
2 1  expressions2 1  expressions
2 1 expressions
 

More from Aakash Singh

Industrial engineering
Industrial engineeringIndustrial engineering
Industrial engineering
Aakash Singh
 
Laurent's Series & Types of Singularities
Laurent's Series & Types of SingularitiesLaurent's Series & Types of Singularities
Laurent's Series & Types of Singularities
Aakash Singh
 
Theory of Production and Costs & Cost Concepts
Theory of Production and Costs & Cost ConceptsTheory of Production and Costs & Cost Concepts
Theory of Production and Costs & Cost Concepts
Aakash Singh
 
Drilling Machine
Drilling MachineDrilling Machine
Drilling Machine
Aakash Singh
 
Entropy
EntropyEntropy
Entropy
Aakash Singh
 
C Language
C LanguageC Language
C Language
Aakash Singh
 
Resume
ResumeResume
Resume
Aakash Singh
 
Building Materials And Construction
Building Materials And ConstructionBuilding Materials And Construction
Building Materials And Construction
Aakash Singh
 
Indeterminate Forms and L' Hospital Rule
Indeterminate Forms and L' Hospital RuleIndeterminate Forms and L' Hospital Rule
Indeterminate Forms and L' Hospital Rule
Aakash Singh
 

More from Aakash Singh (9)

Industrial engineering
Industrial engineeringIndustrial engineering
Industrial engineering
 
Laurent's Series & Types of Singularities
Laurent's Series & Types of SingularitiesLaurent's Series & Types of Singularities
Laurent's Series & Types of Singularities
 
Theory of Production and Costs & Cost Concepts
Theory of Production and Costs & Cost ConceptsTheory of Production and Costs & Cost Concepts
Theory of Production and Costs & Cost Concepts
 
Drilling Machine
Drilling MachineDrilling Machine
Drilling Machine
 
Entropy
EntropyEntropy
Entropy
 
C Language
C LanguageC Language
C Language
 
Resume
ResumeResume
Resume
 
Building Materials And Construction
Building Materials And ConstructionBuilding Materials And Construction
Building Materials And Construction
 
Indeterminate Forms and L' Hospital Rule
Indeterminate Forms and L' Hospital RuleIndeterminate Forms and L' Hospital Rule
Indeterminate Forms and L' Hospital Rule
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 

Type Conversion, Precedence and Associativity

  • 1. Type Conversion Precedence & Associativity - Aakash Singh C Learners
  • 2. Type Conversion  What is Type Conversion? • Type Casting or Type Conversion is a way to convert a variable from one data type to another data type. • For example, if you want to store a long value into a simple integer then you can type cast long to int. 2
  • 3. Type Conversion  Types of Type Conversion • There are two types of type conversion – 1. Implicit Type Conversion 2. Explicit Type Conversion 3
  • 4. 1. Implicit Type Conversion  What is Implicit Type Conversion? • C automatically converts any intermediate values to the proper type so that the expression can be evaluated without losing any significance. • This automatic conversion is known implicit type conversion. • If the operands are of different types, the ‘lower type’ is automatically converted to the ‘higher’ type before the operation proceeds. • The result is of the higher type. 4
  • 5. Implicit Type Conversion short char int Unsigned int long int Unsigned long int float double long double Conversion Hierarchy C uses rule that, in all expressions except assignments, any implicit type conversions are made from a lower size to a higher size type as shown below. This hierarchy can be used while evaluating expressions. 5
  • 6. Example of Implicit Type Conversion 6
  • 7. Example of Implicit Type Conversion 7
  • 8. 1. Explicit Type Conversion  What is Explicit Type Conversion? • The type conversion performed by the programmer by posing the data type of the expression of specific type is known as explicit type conversion. • The general form of a cast is : (type-name) expression • Here, ‘type-name’ is one of the standard C data types and the expression may be a constant, variable, or an expression. 8
  • 9. Use of Explicit Type Casting 9 Example Action X=(int)7.5 7.5 is converted to integer by truncation. a = (int)21.3/(int)4.5 Evaluated as (21/4) and the result would be 5. b = (double)sum/n Division is done in floating point mode. y = (int)(a+b) The result of (a+b) is converted to integer. z = (int)a+b a is converted to integer and then added to b. p = cos((double)x) Converts x to double before using it.
  • 10. Example of Explicit Type Conversion 10
  • 11. Example of Explicit Type Conversion 11
  • 12. Precedence & Associativity  What is Precedence? • C has a precedence associated with it. This precedence is used to determine how an expression involving more than one operator is evaluated.  What is Associativity? • The operators at higher level of precedence are evaluated first. • The operators of the same precedence are evaluated either from ‘left to right’ or from ‘right to left’ depending on the level. This is known as the associativity property of an operator. 12
  • 13. Precedence & Associativity 13  Precedence rules decides the order in which different operators are applied.  Associativity rule decides the order in which multiple occurrences of the same level operator are applied.  C Operators with their Precedence & Associativity are listed in the following table.
  • 14. 14 Operator Description Associativity Rank () [] Function call Array element reference Left to right 1 + - ++ -- ! ~ * & sizeof (type) Unary plus Unary minus Increment Decrement Logical Negation Ones complement Pointer reference Address Size of an object Type cast Right to left 2 * / % Multiplication Division Modulus Left to right 3 + - Addition Subtraction Left to right 4 << >> Left shift Right shift Left to right 5
  • 15. 15 Operator Description Associativity Rank < <= > >= Less than Less than or equal to Greater than Greater than or equal to Left to right 6 == != Equality Inequality Left to right 7 & Bitwise AND Left to right 8 ^ Bitwise XOR Left to right 9 | Bitwise OR Left to right 10 && Logical AND Left to right 11 || Logical OR Left to right 12 ?: Conditional expression Right to left 13
  • 16. 16 Operator Description Associativity Rank = *= /= %= += -= &= ^= |= <<= >>= Assignment operators Right to left 14 , Comma operator Left to right 15
  • 17. Summary of operator precedence 17  ‘Comma’ operator has lowest precedence.  ‘Unary Operators’ are operators having highest precedence.  Operators sharing common block in the above table have equal priority or precedence.  While solving expression, equal priority operators are handled on the basis of FIFO [First in First Out] i.e., Operator Coming First is handled First.
  • 20. 20 Please give your precious feedbacks and suggestions at aakashsingh07041997@gmail.com