const_cast is the C++ cast for intentionally adding or removing constness or volatility from an expression's type. It communicates that intent more clearly than a C-style cast. section 5.6
Treat it as a narrow legacy-code tool, especially when adapting C and C++ interfaces. Prefer better-designed code that removes the need for casts, and test carefully when incremental fixes are unavoidable. section 5.6
A deliberate but dangerous conversion
const char msg[] = "Hello, world"; char* p = const_cast<char*>(msg); *(p + 1) = 'a'; The named cast makes the conversion visible, but the write still makes this production-style fix risky. Do not use const_cast merely to silence a compiler diagnostic; first check whether the interface or design can preserve constness. section 5.6
