What Does Volatile Variable Mean?
A volatile variable is a variable that is marked or cast with the keyword "volatile" so that it is established that the variable can be changed by some outside factor, such as the operating system or other software. A volatile variable is useful in multithreaded applications or in other situations where programmers must anticipate changes to the variable other than those that are common within the code module.
Techopedia Explains Volatile Variable
The volatile variable is useful in different programming languages, including parts of the "C suite" (C++, C, and C#) and in Java, a common programming language for the Web. The exact use of a volatile keyword or variable changes with regard to a particular programming language syntax, but generally, variables can be created as volatile, or conditionally declared volatile within code.
One popular use of the volatile keyword for a variable is in writing code to end a loop or terminate a thread. A programmer can write a simple function that will take in the volatile variable value and end the loop based on a given value. The volatile keyword ensures that the program gets a current value for a Boolean or other variable, instead of an obsolete one.