Use of volatile variable

The only difference between a volatile and a non-volatile variable, is that the non-volatile one has a chance to be totally eliminated by the optimizing compiler. So if you don’t want optimizing variable access need to use “volatile” keyword. Reference: Use of volatile