Volatile Variable

Why Trust Techopedia

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.

Advertisements

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.

Advertisements

Related Terms

Margaret Rouse
Technology Expert
Margaret Rouse
Technology Expert

Margaret 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 IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.