- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why do we use a volatile qualifier in C++?
45 Lectures 4.5 hours
66 Lectures 5.5 hours
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/
- Why do we use restrict qualifier in C++?
- Why do we use const qualifier in C++?
- “volatile” qualifier in C
- 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 internal keyword in C#?
- Why do we use comma operator in C#?
- Why do we use modifiers in C/C++?
- Why do we use JSON.stringify() method in jQuery?
- Why do we use DOCTYPES in HTML document?
- Why do we use the params keyword in C#?