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++ ?

  1. A.

    Prevents variable optimization by the compiler

  2. B.

    Makes variable constant

  3. C.

    Allocates variable on heap

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

Explore the full course: Tpsc Assistant Technical Officer