Intermediate Embedded Systems & IoT
Q46 / 100

Why is the "volatile" keyword important when declaring a variable that is modified by an interrupt handler in C for embedded systems?

Correct! Well done.

Incorrect.

The correct answer is A) It tells the compiler not to optimize away or cache reads/writes to that variable, ensuring the main program always reads its current value, which may change unexpectedly due to the interrupt

A

Correct Answer

It tells the compiler not to optimize away or cache reads/writes to that variable, ensuring the main program always reads its current value, which may change unexpectedly due to the interrupt

Explanation

Without "volatile", the compiler might cache a variable's value in a register, missing updates made by an interrupt handler; "volatile" forces every access to read/write the actual memory location.

Progress
46/100