volatile keyword in c
Volatile keyword in C The compilation system they always try to reduce the code size and execution time. It is the duty of the programmer to inform the compiler to stop optimizations.Volatile in C informs the compiler to stop optimizing the code . SYNTAX: (How to Use?) For a variable to be volatile , just write the keyword “volatile” before the data type in the variable definition. For example: Volatile int temp; If we write the volatile after the data type it is also the same Eg: int volatile temp; Where to use it? A variable can be declared as a volatile whenever the value of the variable changes unexpectedly or the value can be changed by something beyond the control of the program such as concurrently executing thread or an Interrupt Service Routine. There are three chances where the value of the variable may change unexpectedly: 1.Memory mapped peripheral registers. 2.Global variables modified b