top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is use of const volatile ?

+6 votes
914 views

Let me put this in other way , const qualifier will not allow to change you the value so what is the need of going with const volatile. Do we really need it in our day to day programming

posted Oct 30, 2013 by Abhay Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
check this for volatile definition
http://queryhome.com/18863/why-we-need-volatile-variables-in-c

now coming to const volatile
An object marked as const volatile will not be permitted to be changed by the code (an error will be raised due to the const qualifier).
As per my understanding.. Volatile means value can be changed within a code and const means value should never be changed.
then my question is what is the meaning/use of taking variable as a const volatile?
const volatile will not be permitted to be changed...
then what is the use of taking volatile and const both together?

1 Answer

0 votes

For example

const volatile int T=10;

const qualifier means that the T cannot be modified through code. If you attempt to do so the compiler will provide a diagnostic. Volatile still means that compiler cannot optimize or reorder access to T.

Practical Usage:

Accessing shared memory in read-only mode.
Accessing hardware registers in read-only mode.
answer Nov 1, 2013 by Deepankar Dubey
Similar Questions
+1 vote

Also can we declare a variable as "constant volatile" ? if yes then what may be the possible reason to do so?

+7 votes

Where we need to use volatile variable? If possible please provide some real time example ?

+2 votes

As Per my understanding, value can be changed within a code and const means value should never be changed.
So,My question is the meaning/use of taking variable as const volatile?

...