volatile modifier in c

All variable in c are by default not volatile. With help of modifier volatile which is keyword of c language you can make any variable as volatile variable.
Properties of volatile variable:

1. A volatile variable can be changed by the background routine of preprocessor. This background routine may be interrupt signals by microprocessor, threads, real times clocks etc.

2. In simple word we can say a value volatile variable which has stored in the memory can be by any external sources.

3. Whenever compiler encounter any reference of volatile variable is always load the value of variable from memory so that if any external source has modified the value in the memory complier will get its updated value.

4. Working principle of volatile variable is opposite to the register variable in c. Hence volatile variables take more execution time than non-volatile variables.

A volatile variable is declared with help of keyword volatile:

int volatile i;

A non-volatile variable is declared without using keyword volatile:

int i;

Question: What is meaning of following declaration in c?
const volatile float f;
register volatile char c;

Post a Comment