answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

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

Wiki User

9y ago

No. A constant is a value that does not ever change. A variable is a value that can be changed but only from within the program. A volatile is value that may be changed from outwith the program.

This answer is:
User Avatar

User Avatar

Wiki User

16y ago

In mathematics, a constant is a known which does not change, i.e. it stays constant. A variable is an unknown which can change depending on circumstances.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Please refer kmshetty.com

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can a Volatile variable be static also?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Difference between static methods and static variables?

StaticIn the C language family, a static variable is one that exists for the lifetime of a compilation unit (a source file or module). A static variable can be declared module-wide, and thus be accessed by all functions defined within the same source file. Such a static variable cannot be directly accessed from other modules, but inner-module API can pass pointers to static variables and modify those through pointers.A static variable can also be declared within a function body, where the usual scope rules apply. A static variable declared within a function is only initialized when the module is initialized (typically when the application loads), and preserves its values over multiple invocations of the function that contains the definition.In C++, a static variable can also be a member of a class definition. Access to a static member variable is governed by the standard access modifiers (private, public, protected), but all instances of this class share the same static variable, and share the same value. Modifying the value of this variable affects all objects of the class.VolatileThe volatile keyword is something all together different, and not in any way an opposite to static. A static variable may or may not be declared volatile, just as a global or local variable can be.The volatile keyword is a hint informing the compiler that the variable's value might change without the compiler's knowledge. Therefore, the compiler's code optimizer cannot make assumptions about the variable's current value, and must always (re-) read the variable's content.Volatile variables are sometimes used in context with interrupt handlers (although those normally benefit from more sophisticated synchronization methods such as semaphores, mutexes or locks). Most typically, volatile variables are used to model hardware registers through variables.For example, consider a hardware register at address 0x1234, containing a single byte. The value of this byte is hardware driven and contains, for example, the current ambient light level in a range of 0..255. Such a register could be modeled with this construct:unsigned char *const volatile lux = (unsigned char *)0x1234;unsigned char firstReading = *lux;unsigned char secondReading = *lux;In this example, the volatile keyword ensures that the second reading is taken from the hardware register again. Without, a good compiler will read the memory address once and assign the same value to both variables.


Why use static variable in programming language?

For C programming, the use of a static variable has two uses: One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in. The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


Is it legal in java to modify a variable in a static method?

It is, provided that the variable is also static or you're referencing the variable through an instance of you class. class MyClass { static int staticVariable; int memberVariable; public static void main(String[] args) { // This is legal. staticVariable = 10; // This is not legal. memberVariable = 10; // This is legal. MyClass mc = new MyClass(); mc.memberVariable = 10; } }

Related questions

Difference between static methods and static variables?

StaticIn the C language family, a static variable is one that exists for the lifetime of a compilation unit (a source file or module). A static variable can be declared module-wide, and thus be accessed by all functions defined within the same source file. Such a static variable cannot be directly accessed from other modules, but inner-module API can pass pointers to static variables and modify those through pointers.A static variable can also be declared within a function body, where the usual scope rules apply. A static variable declared within a function is only initialized when the module is initialized (typically when the application loads), and preserves its values over multiple invocations of the function that contains the definition.In C++, a static variable can also be a member of a class definition. Access to a static member variable is governed by the standard access modifiers (private, public, protected), but all instances of this class share the same static variable, and share the same value. Modifying the value of this variable affects all objects of the class.VolatileThe volatile keyword is something all together different, and not in any way an opposite to static. A static variable may or may not be declared volatile, just as a global or local variable can be.The volatile keyword is a hint informing the compiler that the variable's value might change without the compiler's knowledge. Therefore, the compiler's code optimizer cannot make assumptions about the variable's current value, and must always (re-) read the variable's content.Volatile variables are sometimes used in context with interrupt handlers (although those normally benefit from more sophisticated synchronization methods such as semaphores, mutexes or locks). Most typically, volatile variables are used to model hardware registers through variables.For example, consider a hardware register at address 0x1234, containing a single byte. The value of this byte is hardware driven and contains, for example, the current ambient light level in a range of 0..255. Such a register could be modeled with this construct:unsigned char *const volatile lux = (unsigned char *)0x1234;unsigned char firstReading = *lux;unsigned char secondReading = *lux;In this example, the volatile keyword ensures that the second reading is taken from the hardware register again. Without, a good compiler will read the memory address once and assign the same value to both variables.


What is the difference between a static variable a global variable and a local variable?

A static variable is a variable allocated in static storage. A local variable is a variable declared inside a function. A global variable is a variable declared outside of any class or function. Note that local variables and global variables can both be allocated in static storage.


What is difference between Static and Global variable?

Static may be local of global -local static variable is limited to the function scope. and retain it's value when function is been called . compiler differentiate static variables with a prefix function name while dealing with same name static variable in different functions. - Global static variable is visible to all the function defined in the file and retain it value but it cannot be used outside this file. now Global Variable --- this variable is also visible to all of the functions inside the file but also can be used outside the file via extern keyword.


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


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.


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


Can a variable be both constant and volatile?

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.


How do you create static variables in PHP?

Use the "static" keyword to declare a static variable within a function like shown below. <?php function fun() { static $variable; static $another_variable = ''; } ?>


Why use static variable in programming language?

For C programming, the use of a static variable has two uses: One reason is to hide the variable from other modules. The scope of the static variable is limited to the compilation unit that it is described in. The second use of a static variable is to keep the value of the variable intact through the entire program execution unit.


Can static variable be used inside a static method?

Yes.


What is static variable and how it is declared?

static variables are declared to define a variable as a constant., means if you declare a variable as static the variable becomes costant.syntaxstatic int a=100;this will make the value of a as 100 which is not to be changedWell, no; you think of 'const', which can be used together with static, but not necessarily.Yes you are right bro I was confused it should be const int a=100; then the variable will be a constant.


What is the static variable in the class in c?

A static member variable is local to the class rather than to an object of the class.