1.

What Are Volatile Variables?

Answer»
  • 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.

e.g.:

  • 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.

e.g.:



Discussion

No Comment Found