What is the difference between static_cast, dynamic_cast, const_cast, and reinterpret_cast?

Last updated 21 June 2026

  • static_cast does checked-at-compile-time conversions (numeric, upcasts, void* back to a type). dynamic_cast does runtime-checked polymorphic downcasts via RTTI, returning nullptr or throwing std::bad_cast.

  • const_cast adds/removes const/volatile (modifying an originally const object is UB). reinterpret_cast reinterprets bit patterns and is the most dangerous.

  • Named casts beat C-style casts: they document intent, are grep-able, and restrict allowed conversions.

  • https://blog.devgenius.io/type-casting-in-c-ded8ee760f85
  • https://unscriptedcoding.medium.com/explicit-casting-in-c-6b97aaa04f5b
  • https://learn.microsoft.com/en-us/cpp/cpp/casting-operators?view=msvc-170
  • https://learn.microsoft.com/en-us/cpp/code-quality/code-analysis-for-cpp-corecheck?view=msvc-170
All C++ interview questions