What is an volatile variable?

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


Please Help Members By Posting Answers For Below Questions

Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?

2061


Between macros and functions,which is better to use and why?

1575


Explain null pointer.

628


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

724


is it possible to create your own header files?

648






Differentiate between a structure and a union.

770


Can include files be nested?

634


What is c preprocessor mean?

799


Explain what is the difference between the expression '++a' and 'a++'?

632


Is malloc memset faster than calloc?

622


Where are some collections of useful code fragments and examples?

723


What is the difference between a string and an array?

714


How do you determine the length of a string value that was stored in a variable?

656


a c code by using memory allocation for add ,multiply of sprase matrixes

2306


Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58

1126