What is the use of volatile keyword in c++?  | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 19

What is the use of volatile keyword in c++? 

9th Dec 2017, 1:07 PM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
1 Answer
+ 2
It says compiler not to optimize somethig. It is good to use volatile variables when program itself doesn't use those variables, but something from outside uses them. So if you have int x = 1 while(x == 1) .... It gets optimized to while(true). You can forbid this by using volatile x = 1
9th Dec 2017, 1:17 PM
Daniel Oravec
Daniel Oravec - avatar