In computing, marking a variable as volatile indicates to the compiler that it should not assume that the state of the variable follows the conventionally assumed scope it appears in. It is subject to change without notice regardless of scope.
In my experience so far, an example of this might be when you are developing in C at a lower level. For example, if your program has an interrupt service routine (ISR) that handles external interrupts, this routine might need to update the states of variables in the main program. So you should declare these variables as volatile, because they may be modified outside the conventional scope of the program. I.e. the ISR may run at any time and update variables in your main program regardless of the fact that in conventional sequential programs, the state of those variables should be preserved by scope.
But you cannot know for sure what the ISR may end up doing to the main program.
The effects of the changing a variable outside of scope cannot be predicted. Thus you must declare those variables as volatile so that the compiler doesn't make assumptions about the scope of those variables in its optimizations.
Today felt like a volatile day. Certain things affected me that probably shouldn't have. But you know that the ISR means well. And the programmer should ensure that the main routine gives the ISR a benefit of a doubt.


