Embedded Software Engineer Question:
Download Questions PDF

Do you know what is the use of volatile keyword?


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 Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me what is interrupt latency? How can you reduce it?Explain how to reduce interrupt latency?