SlideShare una empresa de Scribd logo
1 de 8
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

Más contenido relacionado

La actualidad más candente

Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
vishaljot_kaur
 
Conditional operators
Conditional operatorsConditional operators
Conditional operators
BU
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
dishti7
 

La actualidad más candente (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
 

Destacado

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
chen yan
 
Niki Calderone UX Research Portfolio
Niki Calderone UX Research PortfolioNiki Calderone UX Research Portfolio
Niki Calderone UX Research Portfolio
Niki Calderone Canton
 
The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)The Acropolis Hill (3d representations)
The Acropolis Hill (3d representations)
Eleni Georgakopoulou
 

Destacado (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 a 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_casts
Abed Bukhari
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
Vince Vo
 

Similar a 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
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
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 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

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