top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the role of volatile qualifier in c ?

+4 votes
542 views
What is the role of volatile qualifier in c ?
posted Jan 13, 2014 by Dheerendra Dwivedi

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

1 Answer

+1 vote

The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler.

Objects declared as volatile are omitted from optimization because their values can be changed by code outside the scope of current code at any time. The system always reads the current value of a volatile object from the memory location rather than keeping its value in temporary register at the point it is requested, even if a previous instruction asked for a value from the same object. So the simple question is, how can value of a variable change in such a way that compiler cannot predict.

answer Jan 13, 2014 by Atul Mishra
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 ?

+6 votes

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

...