When volatile can be used?

Answers were Sorted based on User's Feedback

When volatile can be used?..

Answer / reejusri

One more thing i want to add in above answer that is if
compiler sees keyword volatile it skips that variable from
optimization of code, becasue since it is very dymanic in
nature and to manage such type of variable for
optimaization is costly.

Is This Answer Correct ?    7 Yes 0 No

When volatile can be used?..

Answer / mustafa

Volatile restricts the compiler in two ways
1-> No optimization algorithm should be applied to this
2-> When ever you need the value of the volatile variable
please take it from the memory.

Is This Answer Correct ?    7 Yes 0 No

When volatile can be used?..

Answer / qqlin

it means this value will be changed unexpectedly. everytime
the program wants to use it, it can only be got from memory
but not from the register directly.

if you want a variable can be accessed by several threads,
you need this key word, like in ISR program, etc.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More C++ General Interview Questions

What issue do auto_ptr objects address?

2 Answers  

Why preincrement operator is faster than postincrement?

5 Answers  

Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?

0 Answers  

What is static function and static class?

4 Answers   HCL,

What is size of a object of following class? class Foo { public: void foo(){} }

2 Answers   CA,

declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator

0 Answers  

Definition of class?

12 Answers  

What is dangling pointers?and what is memory leak?

5 Answers  

Explain the need for "Virtual Destructor"?

2 Answers   Infosys,

Can you explain the term "resource acquisition is initialization?"

1 Answers  

What is conversion constructor?

2 Answers   TCS,

is throwing exception from a constructor not a good practice ?

5 Answers   Ericsson,