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 do you programme Carrier Sense Multiple Access

1501


I need testPalindrome and removeSpace #include #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

2195


What is the use of header?

607


Explain what are the different data types in c?

741


What is the total generic pointer type?

712






What is structure in c language?

606


Write a program to print numbers from 1 to 100 without using loop in c?

623


write a c program to calculate sum of digits till it reduces to a single digit using recursion

2703


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

889


Distinguish between actual and formal arguments.

575


What does emoji p mean?

589


Why functions are used in c?

570


How does selection sort work in c?

606


What is the heap in c?

627


What are the __date__ and __time__ preprocessor commands?

559