Casting in C++
Named casts make intent explicit: `static_cast`, `const_cast`, `reinterpret_cast`, `dynamic_cast`.
Easy
static_cast<float>(sum) / n. Avoid C-style casts — they silently pick a dangerous one. std::bit_cast (C++20) safely reinterprets bytes.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.