MaxLinear Interview Question

Why do we use volatile in C

Interview Answers

Anonymous

May 24, 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

Anonymous

Mar 21, 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.