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 does '\r' and '\b' mean? Please explain with example.

7 Answers  

Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

0 Answers  

What is RTRT tool?can it be used for automation?can it work on packet PC?

3 Answers  

write a c++ program that gives output 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 using looping statement

2 Answers  

When the design recommends static functions?

2 Answers   Symphony,

What is the difference between static link library and dynamic link library?

7 Answers   Tech Mahindra,

What C++ libraries are you proficient with?

1 Answers   Google,

What are the differences between a struct and a class in C++?

6 Answers   Wipro,

Which of the following operator cannot be overloaded?

2 Answers   TCL,

What will happen if I allocate memory using "new" and free it using "free" or allocate sing "calloc" and free it using "delete"?

3 Answers  

implement stack using stack.h headerfile functions

1 Answers   Exilant, GMG, Subex, University,

what is pulse code modulation?

2 Answers   Wipro,