answersLogoWhite

0

What is volatile modifier?

Updated: 8/11/2023
User Avatar

Dineshrajab

Lvl 1
16y ago

Best Answer

Volatile variables are variables that may change value while they are being operated upon. For instance, a hardware clock is constantly updated by the operating system, thus its value is constantly changing. If you refer to the value, you must declare it volatile because the value is outwith the control of the program.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

16y ago

In C, C++, and Java, the keyword "volatile" instructs the Java Virtual Machine (VM) not to assume that the value of a variable in memory isn't changing, even during code that isn't apparently changing the value of the variable. This prevents certain optimizations from happening (for example, using a register to temporarily replace the variable).

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

The volatile attribute for a data type tells the compiler that the data could be modified by some other process outside of the compiler's knowledge. This forces the compiler to reload the data from memory at each sequence point, rather than depending on a temporary copy that might be kept in a register. This degrades optimization, but is essential if the data is shared by some other thread or hardware construct.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is volatile modifier?
Write your answer...
Submit
Still have questions?
magnify glass
imp