What is mutable keyword in C++?

(Last Updated On: February 26, 2019)

Answer: Using mutable keyword in C++ before any data member of a class, data member can be modified inside const function in C++.

We know that in const member function in C++, a member data cannot be changed. For example, in below class, if we try to modify carID variable inside the const function, compiler will flash an error on compile time itself.



So, If we want to allow modification in constant function in c++ program, we have to use mutable keyword before a data member in the class.
Now, the data member is allowed to be modified in cosnt function in C++ program.