volatile in C appeared with the goal of not caching variable values automatically. It will show the machine that it does not cache the value of this variable. Thus, every time he encounters this, he takes the value of this volatile variable from main memory. This mechanism is used because at any time the value can be changed by the OS or by any interrupt. Therefore, using volatile will help us access the value each time.
Wiki