1. Home
  2. Computer Science MCQs
  3. C Programming
  4. What does the volatile qualifier actually guarantee for an…

Added 30 Nov -0001

What does the volatile qualifier actually guarantee for an object in a C program?

  1. Accesses become atomic between threads, so no torn reads or partial writes can ever occur
  2. A hardware memory barrier is inserted around each access to order it against other threads
  3. The object is placed in a memory section that hardware cannot write behind the program's back
  4. Every access written in the abstract machine is performed, so the compiler cannot cache it Correct answer

Correct answer

D. Every access written in the abstract machine is performed, so the compiler cannot cache it

16 views

MCQSEXAM

Explanation

volatile tells the compiler the object may change outside the program's control, so each access must be emitted rather than cached in a register or coalesced with another. It gives no atomicity, no ordering against other threads and no memory barrier; those require std::atomic or explicit fences. Confusing volatile with thread synchronisation is a standard trap, especially for memory-mapped registers.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs