Discussion
What is the purpose of the 'volatile' keyword in programming languages like C/C++ ?
Answer: A
The volatile keyword prevents variable optimization by the compiler.
Declaring a variable volatile tells the compiler its value can change outside the program's visible flow, for example through a memory-mapped hardware register, an interrupt handler or a signal. The compiler must then read and write the variable in memory every time, instead of keeping it in a register or removing 'redundant' accesses.
It does not make a variable constant (that is const), and it does not decide where the variable is stored. It does not enable multi-threading, and in C and C++ it is not a substitute for proper thread synchronisation.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development