What is type casting?

Type casting is used to convert the data type from lower data type to higher data type and vice versa in order to perform operations with different data types in an expression.

Syntax:
Type variable1= (type)variable2;

Types of casting:
1. Implicit typecasting: Implicit typecasting is that typecasting which occurs automatically by the compiler when data type is converted into the higher type from lower.
Eg: short x=500;
Int y;
y=x;

2. Explicit typecasting: Explicit typecasting means that typecasting which does not occur automatically rather when they occur when programmer himself wants to convert a higher data type to lower type or vice-versa.
Eg: short x=500;
int y;
y = (int) x;

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.