
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
“volatile” qualifier in C
Here we will see what is the meaning of volatile qualifier in C++. The volatile qualifier is applied to a variable when we declare it. It is used to tell the compiler, that the value may change at any time. These are some properties of volatile.
- The volatile keyword cannot remove the memory assignment
- It cannot cache the variables in register.
- The value cannot change in order of assignment.
Let us see, how we can use the volatile keyword.
volatile int a; int volatile a;
Here these two declarations are correct. Like other datatypes, we can use volatile pointers, structures, unions etc. The volatile structures and unions can be volatile itself, and their member variables can also be of type volatile.
The volatile is used in different places. For memory mapped peripheral registers, some global variables, that are accessed by some other functions or interrupt service routines, or in some multi-threaded applications, the volatile can be used.
Example
int main (){ int value; value++; }i nt main (){ volatile int value; value++; }
There are two blocks of code. In the first block the volatile keyword is not present. So for the first case, the variable will be copied from memory to CPU register, then the operations are performed. In the second case the volatile is present. So in this case the variable will not be copied from memory to registers.
- Related Articles
- Why do we use a volatile qualifier in C++?
- Const Qualifier in C
- volatile keyword in C#
- What is volatile keyword in C++?
- Why do we use restrict qualifier in C++?
- Why do we use const qualifier in C++?
- Explain the constant type qualifier in C language
- Volatile Storage vs Non-Volatile Storage
- What does the volatile keyword mean in C++?
- Can we make Array volatile using volatile keyword in Java?
- Difference between Volatile Memory and Non-Volatile Memory
- volatile Keyword in Java
- A greedy qualifier in Java Regular Expressions
- A Reluctant qualifier in Java Regular Expressions
- What is the difference between Volatile and Non-Volatile substances?
