SlideShare a Scribd company logo
1 of 8
Download to read offline
Type Cast Operator :
 There are 2 types of type-casting
1. implicit
2. explicit
implicit type casting :
int x='a';
System.out.println(x); //97 .
The compiler is responsible to perform this type casting.
When ever we are assigning lower datatype value to higher datatype variable then
implicit type cast will be performed .
It is also known as Widening or Upcasting.
There is no lose of information in this type casting.
The following are various possible implicit type casting.
Diagram:
Example 1:
int x='a';
System.out.println(x);//97
Note:
 Compiler converts char to int type automatically by implicit type
casting.
Example 2:
double d=10;
System.out.println(d);//10.0
Note:
 Compiler converts int to double type automatically by implicit type
casting.
Explicit type casting:
 Programmer is responsible for this type casting.
 Whenever we are assigning bigger data type value to the smaller data type
variable then explicit type casting is required.
 Also known as Narrowing or down casting.
 There may be a chance of lose of information in this type casting.
 The following are various possible conversions where explicit type casting is
required.
Diagram:
Example-1 :
int x=130;
byte b=(byte)x;
System.out.println(b); //-126
Example 2 :
int x=130;
byte b=x;
System.out.println(b); //CE : possible loss of precision
 When ever we are assigning higher datatype value to lower datatype value
variable by explicit type-casting ,the most significant bits will be lost i.e., we
have considered least significant bits.
Example 3 :
int x=150;
short s=(short)x;
byte b=(byte)x;
System.out.println(s); //150
System.out.println(b); //-106
 When ever we are assigning floating point value to the integral types by explicit
type casting , the digits of after decimal point will be lost .
Example 4:
double d=130.456 ;
int x=(int)d ;
System.out.println(x); //130
byte b=(byte)d ;
System.out.println(b); //-206

More Related Content

What's hot

Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsAmrinder Sidhu
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSaranyaK68
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 
Variables
VariablesVariables
VariablesBU
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
Conditional operators
Conditional operatorsConditional operators
Conditional operatorsBU
 
Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingElsayed Hemayed
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsShameer Ahmed Koya
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsAnuja Lad
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 

What's hot (20)

COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Uppaal Lite
Uppaal LiteUppaal Lite
Uppaal Lite
 
C Operators
C OperatorsC Operators
C Operators
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Learn Java Part 5
Learn Java Part 5Learn Java Part 5
Learn Java Part 5
 
Variables
VariablesVariables
Variables
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Automata
AutomataAutomata
Automata
 
Report on c
Report on cReport on c
Report on c
 
Conditional operators
Conditional operatorsConditional operators
Conditional operators
 
Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andlooping
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Lecture03(c expressions & operators)
Lecture03(c expressions & operators)Lecture03(c expressions & operators)
Lecture03(c expressions & operators)
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 

Viewers also liked

New Items - Constellation 2017
New Items - Constellation 2017New Items - Constellation 2017
New Items - Constellation 2017Gena Feldmann
 
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...Fundraising Script
 
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFT
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFTGO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFT
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFTcontractormarketing911
 
04course reg uc_model_rpt (1)
04course reg uc_model_rpt (1)04course reg uc_model_rpt (1)
04course reg uc_model_rpt (1)Rana Haseeb
 
JG fitness treadmill, JG-1900,JG-1600 series
JG fitness treadmill, JG-1900,JG-1600 seriesJG fitness treadmill, JG-1900,JG-1600 series
JG fitness treadmill, JG-1900,JG-1600 serieschen yan
 
Niki Calderone UX Research Portfolio
Niki Calderone UX Research PortfolioNiki Calderone UX Research Portfolio
Niki Calderone UX Research PortfolioNiki Calderone Canton
 
The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)Eleni Georgakopoulou
 
Metodo de triangulacion en topografia
Metodo de triangulacion en topografiaMetodo de triangulacion en topografia
Metodo de triangulacion en topografiaJOHNNY JARA RAMOS
 
HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE
 HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE
HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPEdanneeledge
 

Viewers also liked (17)

New Items - Constellation 2017
New Items - Constellation 2017New Items - Constellation 2017
New Items - Constellation 2017
 
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...
Equity Crowdfunding Software, Feature Insight of a White Label Equity Crowdfu...
 
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFT
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFTGO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFT
GO RESPONSIVE! ITS TIME TO GIVE YOUR WEBSITE A FACELIFT
 
04course reg uc_model_rpt (1)
04course reg uc_model_rpt (1)04course reg uc_model_rpt (1)
04course reg uc_model_rpt (1)
 
GEDONG SANGA Temples
GEDONG SANGA TemplesGEDONG SANGA Temples
GEDONG SANGA Temples
 
Prezi
PreziPrezi
Prezi
 
YuvaShakthi
YuvaShakthiYuvaShakthi
YuvaShakthi
 
018 4877 power your life 0
018 4877 power your life 0018 4877 power your life 0
018 4877 power your life 0
 
JG fitness treadmill, JG-1900,JG-1600 series
JG fitness treadmill, JG-1900,JG-1600 seriesJG fitness treadmill, JG-1900,JG-1600 series
JG fitness treadmill, JG-1900,JG-1600 series
 
Niki Calderone UX Research Portfolio
Niki Calderone UX Research PortfolioNiki Calderone UX Research Portfolio
Niki Calderone UX Research Portfolio
 
Figurit
FiguritFigurit
Figurit
 
Brochure English
Brochure EnglishBrochure English
Brochure English
 
journal od tourims_11 (4)
journal od tourims_11 (4)journal od tourims_11 (4)
journal od tourims_11 (4)
 
Tic
TicTic
Tic
 
The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)
 
Metodo de triangulacion en topografia
Metodo de triangulacion en topografiaMetodo de triangulacion en topografia
Metodo de triangulacion en topografia
 
HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE
 HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE
HOW TO CHOOSE A BIKINI FOR YOUR BODY TYPE
 

Similar to Type cast operator

Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++Danial Mirza
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
Lesson 17. Pattern 9. Mixed arithmetic
Lesson 17. Pattern 9. Mixed arithmeticLesson 17. Pattern 9. Mixed arithmetic
Lesson 17. Pattern 9. Mixed arithmeticPVS-Studio
 
Type Conversion in C++ and C# Arithmetic Expressions
Type Conversion in C++ and C# Arithmetic ExpressionsType Conversion in C++ and C# Arithmetic Expressions
Type Conversion in C++ and C# Arithmetic ExpressionsPVS-Studio
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programmingRumman Ansari
 
data types in C-Sharp (C#)
data types in C-Sharp (C#)data types in C-Sharp (C#)
data types in C-Sharp (C#)Abid Kohistani
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic Manzoor ALam
 
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
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Blue Elephant Consulting
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3Vince Vo
 
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIIntro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIBlue Elephant Consulting
 
L3_Tokens, Expression Evaluation.pptx
L3_Tokens, Expression Evaluation.pptxL3_Tokens, Expression Evaluation.pptx
L3_Tokens, Expression Evaluation.pptxSarowarSuman
 

Similar to Type cast operator (20)

Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
Lesson 17. Pattern 9. Mixed arithmetic
Lesson 17. Pattern 9. Mixed arithmeticLesson 17. Pattern 9. Mixed arithmetic
Lesson 17. Pattern 9. Mixed arithmetic
 
Introduction To C
Introduction To CIntroduction To C
Introduction To C
 
Type Conversion in C++ and C# Arithmetic Expressions
Type Conversion in C++ and C# Arithmetic ExpressionsType Conversion in C++ and C# Arithmetic Expressions
Type Conversion in C++ and C# Arithmetic Expressions
 
keyword
keywordkeyword
keyword
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
data types in C-Sharp (C#)
data types in C-Sharp (C#)data types in C-Sharp (C#)
data types in C-Sharp (C#)
 
C PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptxC PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptx
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Declaration of variables
Declaration of variablesDeclaration of variables
Declaration of variables
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
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++
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
 
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part IIIIntro To C++ - Class 04 - An Introduction To C++ Programming, Part III
Intro To C++ - Class 04 - An Introduction To C++ Programming, Part III
 
L3_Tokens, Expression Evaluation.pptx
L3_Tokens, Expression Evaluation.pptxL3_Tokens, Expression Evaluation.pptx
L3_Tokens, Expression Evaluation.pptx
 

Recently uploaded

Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxAvaniJani1
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxMadhavi Dharankar
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 

Recently uploaded (20)

Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 
Introduction to Research ,Need for research, Need for design of Experiments, ...
Introduction to Research ,Need for research, Need for design of Experiments, ...Introduction to Research ,Need for research, Need for design of Experiments, ...
Introduction to Research ,Need for research, Need for design of Experiments, ...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptx
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 

Type cast operator

  • 1. Type Cast Operator :  There are 2 types of type-casting 1. implicit 2. explicit implicit type casting : int x='a'; System.out.println(x); //97 .
  • 2. The compiler is responsible to perform this type casting. When ever we are assigning lower datatype value to higher datatype variable then implicit type cast will be performed . It is also known as Widening or Upcasting. There is no lose of information in this type casting. The following are various possible implicit type casting. Diagram:
  • 3. Example 1: int x='a'; System.out.println(x);//97 Note:  Compiler converts char to int type automatically by implicit type casting. Example 2: double d=10; System.out.println(d);//10.0 Note:  Compiler converts int to double type automatically by implicit type casting.
  • 4. Explicit type casting:  Programmer is responsible for this type casting.  Whenever we are assigning bigger data type value to the smaller data type variable then explicit type casting is required.  Also known as Narrowing or down casting.  There may be a chance of lose of information in this type casting.
  • 5.  The following are various possible conversions where explicit type casting is required. Diagram:
  • 6. Example-1 : int x=130; byte b=(byte)x; System.out.println(b); //-126
  • 7. Example 2 : int x=130; byte b=x; System.out.println(b); //CE : possible loss of precision  When ever we are assigning higher datatype value to lower datatype value variable by explicit type-casting ,the most significant bits will be lost i.e., we have considered least significant bits. Example 3 : int x=150; short s=(short)x; byte b=(byte)x; System.out.println(s); //150 System.out.println(b); //-106
  • 8.  When ever we are assigning floating point value to the integral types by explicit type casting , the digits of after decimal point will be lost . Example 4: double d=130.456 ; int x=(int)d ; System.out.println(x); //130 byte b=(byte)d ; System.out.println(b); //-206