engineering computer science MCQ #2130

What is the purpose of `volatile` keyword?

engineering computer science MCQ #2130

  1. Question 1

    Q1. What is the purpose of `volatile` keyword?

    • A) To optimize variable access
    • B) To inform the compiler that a variable's value can change unexpectedly
    • C) To declare a constant
    • D) To allocate memory on the heap

    Answer: To inform the compiler that a variable's value can change unexpectedly

    Explanation: Volatile keyword tells the compiler to always read a variable's value from memory, not from a register.