What is the purpose of the 'volatile' keyword in programming languages like…
2026
What is the purpose of the 'volatile' keyword in programming languages like C/C++ ?
- A.
Prevents variable optimization by the compiler
- B.
Makes variable constant
- C.
Allocates variable on heap
- D.
Enables multi-threading
Attempted by 74 students.
Show answer & explanation
Correct answer: A
The 'volatile' keyword prevents compiler optimizations on specific variables, ensuring direct memory access for hardware interrupts or multi-threaded scenarios.