type casting or type conversion allows us to convert one data types into another.for type casting cast operator is required.
Syntax:-- (type)expression or value;
Example:
int f =9/4; //without type casting
o/p=2
float f=(float)9/4; //with type casting
o/p=2.3
Type conversion are of two types:
1)Implicit Type Conversion:- it is also known as automatic type conversion.When the type conversion is performed automatically by the compiler,such type of conversion is known as implicit type conversion.
2)Explicit Type Conversion:- the type conversion performed by the programmer is known as explicit type conversion.which is done by cast operator as above mentioned.
Syntax:-- (type)expression or value;
Example:
int f =9/4; //without type casting
o/p=2
float f=(float)9/4; //with type casting
o/p=2.3
Type conversion are of two types:
1)Implicit Type Conversion:- it is also known as automatic type conversion.When the type conversion is performed automatically by the compiler,such type of conversion is known as implicit type conversion.
2)Explicit Type Conversion:- the type conversion performed by the programmer is known as explicit type conversion.which is done by cast operator as above mentioned.
Comments
Post a Comment