The const qualifier tells the compiler that the variable’s value should not be changed once it has been initialized. If we declare a const variable as
Const int k=55;
then any subsequent attempt to modify the variable k will be flagged as an error by the compiler. The const qualifier can also be used by the compiler to perform certain compiler optimizations like placing these variables in a special read-only memory block.
The Volatile qualifier tells the compiler not to perform any optimizations on the variable. One of the optimizations that is performed by most modern computers is to place some variables in the cache memory instead of the main memory to optimize speed of access. The volati1 e qualifier specifies that the variable is heavily used and could be shared by some other programs running in parallel (either in a multithreaded environment or using some interrupt based scheme). Therefore, variables qualified as vo1atil e should not be optimized in any manner and should be stored in the main memory at all times.