
- 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
Why do we use a volatile qualifier in C++?
volatile means two things −
The value of the variable may change without any code of yours changing it. Therefore whenever the compiler reads the value of the variable, it may not assume that it is the same as the last time it was read, or that it is the same as the last value stored, but it must be read again.
The act of storing a value to a volatile variable is a "side effect" which can be observed from the outside, so the compiler is not allowed to remove the act of storing a value; for example, if two values are stored in a row, then the compiler must actually store the value twice.
As an example:
i = 2; i = i;
The compiler must store the number two, read the variable I, store the variable that it read into i.
You can find more details on the volatile keyword here: www.geeksforgeeks.org/understanding-volatile-qualifier-in-c/
- Related Articles
- Why do we use restrict qualifier in C++?
- Why do we use const qualifier in C++?
- “volatile” qualifier in C
- Why do we use modifiers in C/C++?
- Why do we use comma operator in C#?
- Why do we use internal keyword in C#?
- Why do we use extern "C" in C++ code?
- Why do we use the params keyword in C#?
- In JavaScript Why do we use \"use strict\"?
- Why do we use "use strict" in JavaScript?
- Why do we use interfaces in Java?
- Why do we use random.seed() in Python?
- Why do we use pandas in python?
- Why do we use brackets in BODMAS?
- Why do we Use JavaScript in HTML?
