Can someone explain where we use volatile in real time? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone explain where we use volatile in real time?

I know this when we use volatile with variable that means we are instructing a compiler to access a variable everytime form main memory. in simple words volatile avoids optimization of a variable.

28th Feb 2017, 9:59 AM
Venkata Subba Reddy Gowru
Venkata Subba Reddy Gowru - avatar
1 Answer
+ 2
I believe the volatile modifier makes the variable to be read from memory before every arithmetics on it. Especially (and only tbh) useful in multi-threaded enviroment where two or more threads might read/write a variable at the same time.
5th Mar 2017, 12:59 PM
Norbivar
Norbivar - avatar