answersLogoWhite

0

Can a variable be both constant and volatile?

Updated: 8/17/2019
User Avatar

Wiki User

13y ago

Best Answer

This would technically depend on the programming language, but there is no reason for a constant to be declared volatile.

In most languages, a volatile variable is one which may be shared by multiple threads and which also may change at any time. The volatile keyword is used to tell the computer not to cache the value of the variable.

Since constants cannot change, there is no reason that multiple threads would have a problem reading from it at the same time.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can a variable be both constant and volatile?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a variable plus a variable?

A variable is a named memory location for which the contents are volatile. The antonym of variable is constant.


Can a Volatile variable be static also?

Probably; I don't see anything in the standard that says you can't. However, the use of the volatile keyword is usually in embedded code, or multi-threading in which you don't want the compiler to do optimizations on the variable itself.Yes, sure.


What are similarities between an independent variable and a constant variable?

Well, they're both variables.


What is the constant and variable of 6x?

The constant is the number; the variable is the letter.


What is the difference between constant velocity and variable velocity?

Constant velocity has speed always constant along the direction with respect to time. Variable velocity changes its speed with respect to time. Constant velocity has zero acceleration. Variable velocity has non-zero acceleration . An object moving at a constant velocity maintains both the same speed and direction. An object moving at a variable velocity can be changing speed or direction of travel or both.


What is volatile and why are using in java?

volatile variable is mainly used in multithreading environment. so let me explain it from that context.In a multithreading environment,for a variable which is not marked as volatile will be stored in local cache memory for each thread. Meaning each thread will have a local copy of the variable and they dont know about what value this variable is having in another thread. If a variable is marked volatile, then the updations to this variable will happen in the main memory and not in local cache


What is the constant variable in Avogadro's law?

The question is about an oxymoronic expression. A constant cannot be a variable and a variable cannot be a constant!


What a variable that does not change in an experiment is called a constant?

Constant variable


What is main difference between declaring variable and volatile variable?

In languages like C, declaring a variable "volatile" tells the compiler that it can't assume that the variable is only changed by the program code. If the variable is not declared volatile, sometimes the compiler can make certain optimizations since it can assume that it knows everything about how the variable will be used. When it is declared volatile, the variable may be changed by an external process (for example, it could be connected to an I/O device), so it must always be fetched from memory. For a better explanation, see the related links.


Is a constant a number variable or the product of a number and one or more variables?

A constant is not a variable at all, and none of its factors was a variable. It is constant.


What is the opposite of the word constant?

The opposite of the word "constant" is "variable".


What does a constant do in c plus plus?

A constant is a variable that does not change. The correct term is constant variable.