Interview Question

What is volatile?

volatile preserves required accesses but is not a threading synchronization tool.

💡 Concept ✅ Quick Revision ⚙ C

Answer

volatile qualifies an object whose value may change in ways unknown to the implementation. • Accesses through volatile-qualified lvalues are observable side effects under the implementation’s rules. • It is used for cases such as memory-mapped device registers or signal-visible objects. • volatile does not provide atomicity or inter-thread synchronization.

💡 C Example

volatile unsigned int *device_status = (volatile unsigned int *)0x40000000u; /* Platform-specific address; do not run on an ordinary host. */

⚡ Quick Revision

volatile preserves required accesses but is not a threading synchronization tool.