Search⌘ K

Volatile

Explore the volatile keyword in C++ to understand how it designates variables that may change outside normal program flow. Learn why it differs from std::atomic and how volatile ensures direct memory access, which is crucial for embedded systems and handling external I/O events.

Definition #

The volatile variable is one whose value may change due to an external event.

Usually, we can only change the value of a variable within our code. Let’s say there is an external I/O event that tries to change the value of the variable. This would not be allowed.

However, it would be possible if the variable was volatile. A volatile variable can be declared using the ...