SlideShare a Scribd company logo
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

PDF
Lecture 1.3 A Simple Program to Print a Line of Text.pdf
PDF
Lecture 2.8 Arrays.pdf
PDF
Lecture 2.2 Default Arguments.pdf
PDF
Lecture 2.6 Function Templates.pdf
PDF
Lecture 2.4 Recursion.pdf
PDF
Lecture 3 Structures in C++.pdf
PDF
Lecture 2.5 Function Overloading.pdf
PDF
Lecture 1.11 Break and Continue Statements.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 2.8 Arrays.pdf
Lecture 2.2 Default Arguments.pdf
Lecture 2.6 Function Templates.pdf
Lecture 2.4 Recursion.pdf
Lecture 3 Structures in C++.pdf
Lecture 2.5 Function Overloading.pdf
Lecture 1.11 Break and Continue Statements.pdf

More from MianSaeedAkbar1 (12)

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

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Classroom Observation Tools for Teachers
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Lesson notes of climatology university.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Institutional Correction lecture only . . .
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O7-L3 Supply Chain Operations - ICLT Program
PPH.pptx obstetrics and gynecology in nursing
Classroom Observation Tools for Teachers
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Types and Its function , kingdom of life
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Lesson notes of climatology university.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Institutional Correction lecture only . . .
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
Abdominal Access Techniques with Prof. Dr. R K Mishra
Ad

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