The volatile qualifier maintains consistency of memory access to data objects. Volatile objects are read from memory each time their value is needed, and written back to memory each time they are changed. The volatile qualifier declares a data object that can have its value changed in ways outside the control or detection of the compiler (such as a variable updated by the system clock or by another program). This prevents the compiler from optimizing code referring to the object by storing the object's value in a register and re-reading it from there, rather than from memory, where it may have changed.
Accessing any lvalue expression that is volatile-qualified produces a side effect. A side effect means that the state of the execution environment changes.
volatile int * pvol;
int *ptr;
pvol = ptr; /* Legal */
ptr = (int *)pvol; /* Explicit cast required */
A signal-handling function may store a value in a variable of type sig_atomic_t, provided that the variable is declared volatile. This is an exception to the rule that a signal-handling function may not access variables with static storage duration.
An item can be both const and volatile. In this case the item cannot be legitimately modified by its own program but can be modified by some asynchronous process.