Declaring a volatile variable means, you are instructing compiler not to optimize the code snippet around that variable. This is to force the cpu to NOT to use the variable value from local registers or cache memory but to fetch the value from main memory every time.