Type Casting in C++
Level 281 keystrokes
Converts the double 3.14159 to an int with static_cast; the fractional part is dropped, so 3 is printed.
C++ code
// Stores an approximation of pi in a double (a floating-point number)1double pi = 3.14159;// static_cast<int> converts the value to int explicitly// The conversion truncates toward zero instead of rounding: 3.14159 becomes 32int rounded = static_cast<int>(pi);// Prints the converted value, 33cout << rounded << endl;Output
3
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 5;× 3=× 2_× 1.× 1(× 1)× 1>× 1