SlideShare a Scribd company logo
1 of 3
Download to read offline
TYPE CONVERSION IN C++ Lecture 2.7
Prepared by: Mian Saeed Akbar
TYPE CONVERSION IN C++
Argument Coercion
o Force arguments to be of proper type
• Converting int (4) to double (4.0)
o Conversion rules
 Arguments usually converted automatically
 Changing from double to int can truncate data
 3.4 to 3
 Mixed type goes to highest type (promotion)
 int * double
cout << sqrt(4)
Type Conversion / Casting
1. Coercion / Implicit type
Conversion / promotion
2. Truncation / Explicit type
Conversion
int x = int(45.0); int x = (int)45.0;
Thank you
Please subscribe my channel for more videos
and courses

More Related Content

More from MianSaeedAkbar1

Lecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfLecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfMianSaeedAkbar1
 
Lecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfLecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfMianSaeedAkbar1
 
Lecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfLecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfMianSaeedAkbar1
 
Lecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfLecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfMianSaeedAkbar1
 
Lecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfLecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfMianSaeedAkbar1
 
Lecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfLecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfMianSaeedAkbar1
 
Lecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfLecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfMianSaeedAkbar1
 
Lecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfLecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfMianSaeedAkbar1
 
Lecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfLecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfMianSaeedAkbar1
 
Lecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfLecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfMianSaeedAkbar1
 
Lecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfLecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfMianSaeedAkbar1
 
Lecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfLecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfMianSaeedAkbar1
 

More from MianSaeedAkbar1 (12)

Lecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfLecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdf
 
Lecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfLecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdf
 
Lecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfLecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdf
 
Lecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfLecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdf
 
Lecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfLecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdf
 
Lecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfLecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdf
 
Lecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfLecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdf
 
Lecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfLecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdf
 
Lecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfLecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdf
 
Lecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfLecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdf
 
Lecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfLecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdf
 
Lecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfLecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdf
 

Recently uploaded

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Recently uploaded (20)

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Lecture 2.7 Type Conversion in C++.pdf

  • 1. TYPE CONVERSION IN C++ Lecture 2.7 Prepared by: Mian Saeed Akbar
  • 2. TYPE CONVERSION IN C++ Argument Coercion o Force arguments to be of proper type • Converting int (4) to double (4.0) o Conversion rules  Arguments usually converted automatically  Changing from double to int can truncate data  3.4 to 3  Mixed type goes to highest type (promotion)  int * double cout << sqrt(4) Type Conversion / Casting 1. Coercion / Implicit type Conversion / promotion 2. Truncation / Explicit type Conversion int x = int(45.0); int x = (int)45.0;
  • 3. Thank you Please subscribe my channel for more videos and courses