Use of Volatile keyword in C programing
A variable should be qualified as a “volatile”,when there is possibility that it can be changed by something beyond the control of the program in which it appears.
Let there is data type P.
then this data type P can be declared like
The volatile qualifier like int a = 3, declares and initialize int a and value of a will be always read from memory.
volatile int a,int b;
Use of volatile
- Memory map i/o port
- A variable that is shared between concurrent process
- A object/variable modified by interupt service routine
- A local variable declared in function that calls setjmp and whose value is changed between call to setjmp and coresponding call to longjmp.
- #A local variable declared in function that calls setjmp and whose value is changed between call to setjmp and corresponding call to longjmp.
static jmp_buf tempBuf;
volatile int b;
b = 3;
printf("%d \n",b) ;
b = 5;