I. const Qualifier
A const qualifier tells the C compiler that the value of a variable cannot be changed after its
initialization. For example,
const float pi = 3.1417;
That is, now pi cannot be changed throughout the program.
Another way of doing this is using the #define preprocessor directive as follows:
#define PI 3.1417
But please remember that const and #define are different.
#define constants are declared at
the beginning of the program, even before main( ). On the other hand,
const variables can be
placed anywhere within the program.
So const has finer control than #define. #define cannot be
placed anywhere in the program. This gives an error.
II. Volatile Qualifier
The volatile qualifier declares a data type that can have its value changed in ways outside the
control or detection of the compiler, like a variable updated by the system clock.
This prevents
the compiler from optimizing code referring to the object by storing the object’s value in a register
and rereading it from there rather than from memory, where it may have changed.
Do'stlaringiz bilan baham: |