Domanda di colloquio di MaxLinear

Why do we use volatile in C

Risposte di colloquio

Anonimo

24 mag 2011

Elaborating on WHY it needs to be volatile is that it's basically a hint to the compiler not to cache the data / variable in a register as it will most likely be modified externally.

5

Anonimo

21 mar 2010

The variable which needs to be updated very often then that variable should be declared as volatile. The variables that need to updated based on interrupt then that variable should be defined as volatile. Ex:time, whenever interrupt occurs for time the clock tick increments which will be declared as volatile.