It is used when programming at a low level with interrupts, etc. primarily
volatile int count;
void test()
{
while(count< 100)
{
}
}
void interrupt()
{
count = count + 1;
}
if you do not declare the variable as volatile, the compiler will probably notice that the counter cannot change during the while loop, and therefore will not worry about actually reading the value each time from memory so that it never exits the loop.
volatile, , , ...
- .
, "" . , , , , . volatile , , , , , , , .
, .
: , ++, , . . .. - , , .
" ", volatile. BAD ADVICE , , "", . , , , , , "", . . , , ++ 11 , (, ++ 11)