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 a lvalue
In which header file is the null macro defined?
What is 'bus error'?
What are volatile variables in c?
Can stdout be forced to print somewhere other than the screen?
What is const keyword in c?
What is the difference between single charater constant and string constant?
How can I call fortran?
How can I remove the leading spaces from a string?
How is a pointer variable declared?
Sir i need notes for structure,functions,pointers in c language can you help me please
Explain what are multidimensional arrays?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
What is structure in c language?
What are multidimensional arrays?