Is this undefined behavior with const_cast? [duplicate]
Quote from cppreference: Even though const_cast may remove constness or volatility from any pointer or reference, using the resulting pointer or reference to write to an object that was declared const or to access an object that was declared volatile invokes undefined behavior. So yes, modifying constant variables is undefined behavior. The output you see … Read more