SlideShare a Scribd company logo
1 of 19
Prepared By: Asst. Prof. Sejal Jadav
Unit-1
Principles of Object Oriented Programming Tokens,
expressions & Control Statements
(14 MARKS)
B.C.A & B.Sc.(IT) – 3
CS-13 C++ and Object Oriented
Programming
Prepared By: Asst. Prof. Sejal Jadav
Operators
• Input/output operators
• << output / insertion operator
• >> input / extraction operator
• Scope resolution operator
• ::
• Memory management operators
• New-memory allocation
operator
• Delete-memory release operator
• Member dereferencing operator
• ::* pointer-to-member declarator
• ->*pointer-to-member operator
• .* pointer-to-member operator
• Manipulators
• Endl-line feed operator
• Setw-field width operator
• Type cast operator
• Definition : An operator is a symbol that tells the compiler to
perform specific mathematical or logical manipulations.
Prepared By: Asst. Prof. Sejal Jadav
Scope Resolution Operator
• We know that the same variable name can be used in
different blocks in C++
• The scope of the variable extends from the point of its
declaration till the end of the block containing the
declaration.
Prepared By: Asst. Prof. Sejal Jadav
• The variable declared inside the block is called local
variable to that block.
• While blocks are nested the declaration in inner block
hides a declaration of the same variable in an outer
block.
Prepared By: Asst. Prof. Sejal Jadav
• Hence in C – language the global variable cannot be
accessed from the inner block.
• C++ resolves this problem by introducing a new
operator : : called scope resolution operator.
Prepared By: Asst. Prof. Sejal Jadav
Syntax :
: : variable_name
• This operator allows global version of the variable.
• Let’s see Example……. 12_scope_operator.cpp
Prepared By: Asst. Prof. Sejal Jadav
Type cast operator
• Type casting is a way to convert a variable
from one data type to another datatype.
• For example, if you want to store a long value into a
simple integer then you can typecast long to int.
• You can convert values from one type to another
explicitly using the cast operator.
Prepared By: Asst. Prof. Sejal Jadav
•There are two types of type conversion in C++.
1. Implicit Conversion
2. Explicit Conversion (also known as Type
Casting)
Prepared By: Asst. Prof. Sejal Jadav
Implicit Type Conversion
• The type conversion that is done automatically done
by the compiler is known as implicit type conversion.
• This type of conversion is also known as automatic
conversion.
• Let’s look at examples: 01_typecast, 02_typecast.cpp
Prepared By: Asst. Prof. Sejal Jadav
int main() {
int num_int = 9;
double num_double;
num_double = num_int;
cout << "num_int = " << num_int << endl;
cout << "num_double = " << num_double << endl;
}
Output
num_int = 9
num_double = 9
Prepared By: Asst. Prof. Sejal Jadav
• In the program, we have assigned an int data to a
double variable.
num_double = num_int;
• Here, the int value is automatically converted to
double by the compiler before it is assigned to the
num_double variable. This is an example of implicit
type conversion.
Prepared By: Asst. Prof. Sejal Jadav
Data Loss During Conversion (Narrowing Conversion)
• As we have seen from the above example, conversion
from one data type to another is to data loss.
• This happens when data of a larger type is converted
to data of a smaller type.
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
C++ Explicit Conversion
• When the user manually changes data from one type
to another, this is known as explicit conversion.
• This type of conversion is also known as type
casting.
Prepared By: Asst. Prof. Sejal Jadav
• There are three major ways in which we can use
explicit conversion in C++. They are:
1. C-style type casting (also known as cast notation)
2. Function notation (also known as old C++ style
type casting)
3. Type conversion operators
Prepared By: Asst. Prof. Sejal Jadav
C-style Type Casting
• As the name suggests, this type of casting is favored
by the C programming language. It is also known as
cast notation.
• The syntax for this style is:
(data_type)expression;
Prepared By: Asst. Prof. Sejal Jadav
For example,
// initializing int variable
int num_int = 26;
// declaring double variable
double num_double;
// converting from int to double
num_double = (double)num_int;
Prepared By: Asst. Prof. Sejal Jadav
Function-style Casting
• We can also use the function like notation to cast data
from one type to another.
• The syntax for this style is:
data_type(expression);
Prepared By: Asst. Prof. Sejal Jadav
For example,
// initializing int variable
int num_int = 26;
// declaring double variable
double num_double;
// converting from int to double
num_double = double(num_int);

More Related Content

What's hot

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts246paa
 
Object oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingObject oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingVaibhav Khanna
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections FrameworkGhadeer AlHasan
 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective CTiyasi Acharya
 
Practice Session
Practice Session Practice Session
Practice Session Hitesh-Java
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and OverloadingGhadeer AlHasan
 
Concepts of OOPs
Concepts of OOPsConcepts of OOPs
Concepts of OOPsEssay Corp
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introductionsandeep54552
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++sandeep54552
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesTushar B Kute
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetHDR1001
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IAjit Nayak
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 

What's hot (20)

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingObject oriented programming 2 elements of programming
Object oriented programming 2 elements of programming
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections Framework
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective C
 
Practice Session
Practice Session Practice Session
Practice Session
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading
 
Concepts of OOPs
Concepts of OOPsConcepts of OOPs
Concepts of OOPs
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Lecture02
Lecture02Lecture02
Lecture02
 
class and objects
class and objectsclass and objects
class and objects
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 

Similar to C++ Operators and Type Casting

C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7Jadavsejal
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)Dilawar Khan
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12Jadavsejal
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginnersophoeutsen2
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001Ralph Weber
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt8759000398
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in Cbabuk110
 

Similar to C++ Operators and Type Casting (20)

C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Aspdot
AspdotAspdot
Aspdot
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Embedded _c_
Embedded  _c_Embedded  _c_
Embedded _c_
 
C programming
C programming C programming
C programming
 
C programming language
C programming languageC programming language
C programming language
 
Session 06 - Java Basics
Session 06 - Java BasicsSession 06 - Java Basics
Session 06 - Java Basics
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 

More from Jadavsejal

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassJadavsejal
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event HandlingJadavsejal
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingJadavsejal
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout ManagersJadavsejal
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15Jadavsejal
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14Jadavsejal
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8Jadavsejal
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5Jadavsejal
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4Jadavsejal
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2Jadavsejal
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3Jadavsejal
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1Jadavsejal
 
05_system architecture
05_system architecture05_system architecture
05_system architectureJadavsejal
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture Jadavsejal
 
04 authentication
04 authentication04 authentication
04 authenticationJadavsejal
 

More from Jadavsejal (20)

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone Class
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event Handling
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event Handling
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout Managers
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1
 
05_system architecture
05_system architecture05_system architecture
05_system architecture
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture
 
Vpn protocols
Vpn protocolsVpn protocols
Vpn protocols
 
04 authentication
04 authentication04 authentication
04 authentication
 
03 cia
03 cia03 cia
03 cia
 
01
01 01
01
 
4 ipv6
4 ipv64 ipv6
4 ipv6
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 

C++ Operators and Type Casting

  • 1. Prepared By: Asst. Prof. Sejal Jadav Unit-1 Principles of Object Oriented Programming Tokens, expressions & Control Statements (14 MARKS) B.C.A & B.Sc.(IT) – 3 CS-13 C++ and Object Oriented Programming
  • 2. Prepared By: Asst. Prof. Sejal Jadav Operators • Input/output operators • << output / insertion operator • >> input / extraction operator • Scope resolution operator • :: • Memory management operators • New-memory allocation operator • Delete-memory release operator • Member dereferencing operator • ::* pointer-to-member declarator • ->*pointer-to-member operator • .* pointer-to-member operator • Manipulators • Endl-line feed operator • Setw-field width operator • Type cast operator • Definition : An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
  • 3. Prepared By: Asst. Prof. Sejal Jadav Scope Resolution Operator • We know that the same variable name can be used in different blocks in C++ • The scope of the variable extends from the point of its declaration till the end of the block containing the declaration.
  • 4. Prepared By: Asst. Prof. Sejal Jadav • The variable declared inside the block is called local variable to that block. • While blocks are nested the declaration in inner block hides a declaration of the same variable in an outer block.
  • 5. Prepared By: Asst. Prof. Sejal Jadav • Hence in C – language the global variable cannot be accessed from the inner block. • C++ resolves this problem by introducing a new operator : : called scope resolution operator.
  • 6. Prepared By: Asst. Prof. Sejal Jadav Syntax : : : variable_name • This operator allows global version of the variable. • Let’s see Example……. 12_scope_operator.cpp
  • 7. Prepared By: Asst. Prof. Sejal Jadav Type cast operator • Type casting is a way to convert a variable from one data type to another datatype. • For example, if you want to store a long value into a simple integer then you can typecast long to int. • You can convert values from one type to another explicitly using the cast operator.
  • 8. Prepared By: Asst. Prof. Sejal Jadav •There are two types of type conversion in C++. 1. Implicit Conversion 2. Explicit Conversion (also known as Type Casting)
  • 9. Prepared By: Asst. Prof. Sejal Jadav Implicit Type Conversion • The type conversion that is done automatically done by the compiler is known as implicit type conversion. • This type of conversion is also known as automatic conversion. • Let’s look at examples: 01_typecast, 02_typecast.cpp
  • 10. Prepared By: Asst. Prof. Sejal Jadav int main() { int num_int = 9; double num_double; num_double = num_int; cout << "num_int = " << num_int << endl; cout << "num_double = " << num_double << endl; } Output num_int = 9 num_double = 9
  • 11. Prepared By: Asst. Prof. Sejal Jadav • In the program, we have assigned an int data to a double variable. num_double = num_int; • Here, the int value is automatically converted to double by the compiler before it is assigned to the num_double variable. This is an example of implicit type conversion.
  • 12. Prepared By: Asst. Prof. Sejal Jadav Data Loss During Conversion (Narrowing Conversion) • As we have seen from the above example, conversion from one data type to another is to data loss. • This happens when data of a larger type is converted to data of a smaller type.
  • 13. Prepared By: Asst. Prof. Sejal Jadav
  • 14. Prepared By: Asst. Prof. Sejal Jadav C++ Explicit Conversion • When the user manually changes data from one type to another, this is known as explicit conversion. • This type of conversion is also known as type casting.
  • 15. Prepared By: Asst. Prof. Sejal Jadav • There are three major ways in which we can use explicit conversion in C++. They are: 1. C-style type casting (also known as cast notation) 2. Function notation (also known as old C++ style type casting) 3. Type conversion operators
  • 16. Prepared By: Asst. Prof. Sejal Jadav C-style Type Casting • As the name suggests, this type of casting is favored by the C programming language. It is also known as cast notation. • The syntax for this style is: (data_type)expression;
  • 17. Prepared By: Asst. Prof. Sejal Jadav For example, // initializing int variable int num_int = 26; // declaring double variable double num_double; // converting from int to double num_double = (double)num_int;
  • 18. Prepared By: Asst. Prof. Sejal Jadav Function-style Casting • We can also use the function like notation to cast data from one type to another. • The syntax for this style is: data_type(expression);
  • 19. Prepared By: Asst. Prof. Sejal Jadav For example, // initializing int variable int num_int = 26; // declaring double variable double num_double; // converting from int to double num_double = double(num_int);