What are volatile variables?

What are volatile variables?

Volatile variables get special attention from the compiler. A variable declared with the volatile keyword may be modified externally from the declaring function.

If the keyword volatile is not used, the compiler optimization algorithms might consider this to be a case of infinite loop. Declaring a variable volatile indicates to a compiler that there could be external processes that could possibly alter the value of that variable.

A variable that might be concurrently modified by multiple threads may be declared volatile. Variables declared to be volatile will not be optimized by the compiler. Compiler must assume that their values can change at any time. However, operations on a volatile variable are still not guaranteed to be atomic.

What are volatile variables?

Volatile variables are like other variables except that the values might be changed at any given point of time only by ‘some external resources’.


volatile int number;

The value may be altered by some external factor, though if it does not appear to the left of the assignment statement. The compiler will keep track of these volatile variables.
Segmentation violation
A segmentation violation usually indicates an attempt to access memory which doesn't even exist...
What is "Bus error"?
A bus error indicates an attempt to access memory in an illegal way,perhaps due to an unaligned pointer....
Recursion in C
A programming technique in which a function may call itself....
Post your comment