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;
Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of modifiers in c
Rules of using modifiers in c
Possibles modifiers of given data types in c
Size modifier in c
Size of data types in c
Sign modifier in c
Range of data types in c
Easy way to remember limit of data types in c
Const modifiers in c
Pointers modifier in c
Function modifier in c
Interrupt modifier in c
Volatile modifier in c
Fundamental data types in c
Memory representation of char in c
Memory representation of signed char in c
Memory representation of int in c
Memory representation of signed int in c
Memory representation of double in c
3 comments:
Volatile keyword says the compiler that no optimiztion on the variable.The volatile keyword acts as a data type qualifier.
The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code.
const volatile char c; it means the value will be modified only in case of hardware. they cannot modified in software case.
Post a Comment