What is an volatile variable?

Answer Posted / vishal

What is the significance of volatile keyword?
Volatile keyword is used to inform the compiler not to predict/assume/believe/presume the value of the particular variable which has been declared as volatile.



Why/When do we need volatile ?
In following case we need to use volatile variable.




Memory-mapped peripheral registers
Global variables modified by an interrupt service routine
Global variables within a multi-threaded application
If we do not use volatile qualifier the following problems may arise:




Code that works fine-until you turn optimization on
Code that works fine-as long as interrupts are disabled
Flaky hardware drivers
Tasks that work fine in isolation-yet crash when another task is enabled

Source: http://www.firmcodes.com/volatile-keyword-in-c-and-embedded-system/

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I read and write comma-delimited text?

625


What is difference between structure and union in c programming?

575


Why isnt there a numbered, multi-level break statement to break out

595


In C programming, how do you insert quote characters (‘ and “) into the output screen?

900


What are c header files?

587






why do some people write if(0 == x) instead of if(x == 0)?

662


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

1378


Why we use void main in c?

604


How are portions of a program disabled in demo versions?

758


What type of function is main ()?

595


How variables are declared in c?

578


When can you use a pointer with a function?

576


How do you write a program which produces its own source code as output?

614


What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers

685


What are the different types of pointers used in c language?

618