Type Casting

Typecasting is a way to make a variable of one type, such as an int, act like another type, such as a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (float)a will make a as a float.

Syntax

(type_name) expression

Without Type Casting

typecasting1

Output

type1-output

After Type Casting

typecasting2

Output

type1-output2

Note

It’s best practice to convert lower data type to higher data type to avoid data loss