Programming ConceptsLesson 13Free preview
Type Casting
This lesson is part of Intro to Programming · All levels
Summary
This lesson discusses type casting, which is converting a value from one type of data to another type, for example from an integer to a float or vice versa. Casting can be automatically executed in a specific language, or written explicitly by the programmer. You have to be careful when converting to a narrower type because there could be data loss like decimal making.
Key points
- Type casting changes the value from one type to another type
- Implicit casting is done automatically by language; explicit casting is written by the programmer
- Conversion from float to int discard fraction
- An unsafe conversion can lead to data loss
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.