Disclaimer: ChatGPT generated document.
C++ const can be slightly deceptive because there is an important difference between an object that is genuinely const and a mutable object that is merely being accessed through a const pointer or reference. That distinction is the key to understanding when const_cast is safe and when modifying through it causes undefined behavior.
This also raises some related questions: Does it matter whether the object lives on the stack, in static storage, or on the heap? What exactly happens when we write new const T? Why would we deliberately create a dynamically allocated object that can never be modified? And what other qualifiers or forms can be used with a new expression?
