Volatile Variable

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.


Related Terms

Latest DevOps Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…