Type Conversion Flashcards
1
Q
Types of data types?
A
Implicit and explicit
> > NEED COMPATIBLE DATA TYPES, str + int = error
2
Q
Implicit data conversion
A
Value of data type with smaller range is assigned to variable of compatible type with larger range
I.e int -> double
Byte -> short -> int -> long -> float -> double
^
|
Char
Int to float, doesn’t need f for float.
Automatically done
3
Q
Explicit data type conversion
A
Convert larger data type to a smaller range. This can’t be done by compiler implicitly as a possibility of data loss
I.e.
double price = 200;
Int newPrice = (int)price;
Not done automatically