Can A Variable Be Both Const And Volatile? Volatile keyword is useful for memory-mapped peripheral registers, global variables modified by an interrupt service routine, global variables accessed by multiple tasks within a multi-threaded application. In those cases it is required not to optimize the code, doing so may lead to erroneous result and load the variable every time it is used in the program. A variable should be declared volatile whenever its value could change unexpectedly and beyond the comprehension of the compiler. By declaring a variable volatile, we can tell the compiler that the value of the variable may change any moment from outside of the scope of the program. The C's volatile keyword is a qualifier that tells the compiler not to optimize when applied to a variable.