C++20 sections · 1024 units
Open in Course

Type Conversion - Implicit

Silent changes

C++ automatically converts between types when needed. If you assign an int to a double, it adds .0 automatically: double x = 5; becomes 5.0. Conversions from smaller to larger types are safe: int to long long, or float to double.

You do not lose any data in these conversions. Conversions from larger to smaller types can lose data: double x = 3.7; int y = x; silently truncates to y = 3. No warning is given.