VOOZH about

URL: https://www.geeksforgeeks.org/c/use-volatile-keyword-in-c/

⇱ How to Use the Volatile Keyword in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Use the Volatile Keyword in C?

Last Updated : 23 Jul, 2025

In C, the volatile keyword is used to inform the compiler that the value of a variable may change at any time, without any action being taken by the code in the program. It is particularly useful in embedded systems, signal handlers, and multi-threaded applications. In this article, we will learn how to use the volatile keyword in C.

Volatile Keyword in C

We can use the  for different purposes like declaring some global variables, signal handlers, variables across shared threads, etc. When a variable is declared as volatile, it tells the compiler:

  • The compiler must not assume the value of the variable remains constant between accesses, so it should read the value from memory every time it is used.
  • The compiler must not reorder instructions in a way that changes the access order of the volatile variable.

Syntax to Use Volatile Qualifier in C

volatile dataType varName;

C Program to Demonstrate the Use of Volatile Keyword

The below program demonstrates the use of volatile keyword in C.


Output

Final value of volVar: 20
Comment