Computer Science / Unit 7 CS 0365 short lesson, about 20 seconds
Coercion and the Type Cast
Captions available
The idea
Coercion is relaxed type checking — a smaller type's value fits legally into a larger one — while the reverse requires a type cast, forcing a larger value into a smaller space.
In practice
A two-byte count assigned into four bytes passes untouched; the reverse trip needs paperwork.
Where people slip
The paperwork exists because the reverse trip has consequences.
Your place on the trail
Every lesson rests on earlier ones and opens later ones. Tap any to jump.
Builds on
Something wrong in this lesson? Flag it · Sources for Computer Science