What is the use of volatile keyword in C/C++? What is the difference between declaring a variable volatile and not declaring it as volatile?
Volatile tells the compiler that the variable might change without it knowing - so it shouldn't optimise it away.
The only time I have ever needed it was in the days of ISA cards when you read a memory address to get the data from the bus. There was also a bug in the compiler which meant volatile didnt work!
It can also be useful in some parallel / mutli-threaded code