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
variable.
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

Explain function overloading

0 Answers  


Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.

0 Answers  


Consider a c++ template funtion template<class T> T& Add(T a, T b){return a+b ;} if this function is called as T c = Add("SAM", "SUNG"); what will happen? What is the problem in the template declaration/ How to solve the problem.

7 Answers   LG, Samsung,


What is a friend function in c++?

0 Answers  


What is insertion sorting?

0 Answers  






How should a contructor handle a failure?

0 Answers  


What are the advantages of prototyping?

0 Answers  


Define private, protected and public access control.

0 Answers  


Is main a class in c++?

0 Answers  


Can we specify variable field width in a scanf() format string? If possible how?

0 Answers  


Out of fgets() and gets() which function is safe to use and why?

0 Answers  


Show the declaration for a pointer to function returning long and taking an integer parameter.

0 Answers  


Categories