Embedded Software Engineer Question:

Do you know what is the use of volatile keyword?

Tweet Share WhatsApp

Answer:

The C's volatile keyword is a qualifier that tells the compiler not to optimize when applied to a variable. By declaring a variable volatile, we can tell the compiler that the value of the variable may change any moment from outside of the scope of the program. A variable should be declared volatile whenever its value could change unexpectedly and beyond the comprehension of the compiler.

In those cases it is required not to optimize the code, doing so may lead to erroneous result and load the variable every time it is used in the program. Volatile keyword is useful for memory-mapped peripheral registers, global variables modified by an interrupt service routine, global variables accessed by multiple tasks within a multi-threaded application.

Download Embedded Software Engineer PDF Read All 100 Embedded Software Engineer Questions
Previous QuestionNext Question
Tell me what is interrupt latency? How can you reduce it?Explain how to reduce interrupt latency?