Answer Posted / chandrashekar kalvacherla
volatile tells the compiler that this variable can get altered by ways that the compiler cannot deduce. As a consequence, the compiler will exclude that variable from optimizations and the code will always fetch the variables content from memory, even if it has done so before (no caching).
Imagine a hardware clock which is mapped into memory. You need some way to tell the compiler: whenever I access that variable (mapped to the hardware clock), I want you to actually fetch the content from there. Otherwise the compiler might just ask the clock once for the current time and use the cached value (in a processor register) throught the rest of the program.
Is This Answer Correct ? | 8 Yes | 0 No |
Post New Answer View All Answers
What is the use of extern in c?
Simplify the program segment if X = B then C ← true else C ← false
Function calling procedures? and their differences? Why should one go for Call by Reference?
What is the explanation for cyclic nature of data types in c?
Explain how can you be sure that a program follows the ansi c standard?
How variables are declared in c?
What is a static variable in c?
Was 2000 a leap year?
Explain what is wrong in this statement?
Explain the difference between the local variable and global variable in c?
Why do we use main function?
How to throw some light on the b tree?
What is the code in while loop that returns the output of given code?
What are c header files?
Is it better to use malloc() or calloc()?