volatile
The
volatile qualifier indicates that
the variable it is applied to can be
modified by an external entity (a hardware device for example). In this way the
compiler is made aware that no optimization can take place to avoid checking
the variable’s value.
volatile can also
be applied in conjunction with
const,
because also a
const value can be modified
by an external entity.
Example
#include <iostream>
using namespace std;
int main()
{
// both variables can be changed by an external entity
volatile a = 5;
const volatile b = 6;
}