top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Explain the volatile and mutable keywords in C/C++ with an example?

+2 votes
757 views
Explain the volatile and mutable keywords in C/C++ with an example?
posted Apr 4, 2016 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

A variable marked with keyword mutable allows for it to be modified in a method declared const.
This means...
Mutable interacts with const. If we have a const pointer, we normally could not change members. Mutable provides an exception to that rule.

A variable marked with keyword volatile tells the compiler that it must read/write the variable every time.

answer Apr 4, 2016 by Ashutosh Kumar Anand
ariables prefixed with the keyword volatile acts as a data type qualifier. The volatile keyword attempts to alter the default way in which the variables are stored and the way the compiler handles the variables.
It is a kind of instruction to the optimizer to not to optimize the variables during compilation.

http://tech.queryhome.com/74144/what-is-the-meaning-of-volatile-variable-in-c-c
...