Question d’entretien chez MaxLinear

Why do we use volatile in C

Réponses aux questions d'entretien

Utilisateur anonyme

24 mai 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

Utilisateur anonyme

21 mars 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.