- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is volatile keyword 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++; } int 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
- volatile keyword in C#
- What does the volatile keyword mean in C++?
- volatile Keyword in Java
- Can we make Array volatile using volatile keyword in Java?
- What is the difference between Volatile and Non-Volatile substances?
- What are 'Volatile' and 'Non-volatile' substances?
- “volatile” qualifier in C
- What is the const Keyword in C++?
- What is the use of "is" keyword in C#?
- What is the use of ‘new’ keyword in C#?
- What is the difference between transient and volatile in Java?
- What is the C# equivalent of C++ friend keyword?
- Volatile Storage vs Non-Volatile Storage
- What is "namespace" keyword in PHP?
- What is "out" keyword in Kotlin?
