Type Casting:
The process of converting value of
one Datatype to another Datatype. Two ways of Casting:
Widening: Converting a smaller datatype to higher datatype
is called widening.
byte-> short -> char -> int
-> long -> float -> double
widening happens automatically and it
is safe operation. We also call widening as implicit casting.
Ex: int n=10;
float x=n;
Narrowing: Converting a higher datatype to
smaller datatype is called narrowing.
double -> float -> long ->
int -> char -> short -> byte
narrowing happens manually and it is
not safe operation. We also call narrowing as explicit casting.
Ex: float n=10.2f;
int
x=(int)n Output: 10
0 comments:
Post a Comment