I l @ ve RuBoard |
Use the following keywords to qualify variables :
const, volatile
A qualifier constrains a variable's ability to be modified. A const variable, after it's initialized , can't be altered . The compiler can't assume that a volatile variable hasn't been changed by some outside agency, such as a hardware update.
Note
The declaration
const int joy = 101;
establishes that the value of joy is fixed at 101 .
The declaration
volatile unsigned int incoming;
establishes that the value of incoming might change between one occurrence of incoming in a program and its next occurrence.
The declaration
const int * ptr = &joy;
establishes that the pointer ptr can't be used to alter the value of the variable joy . The pointer can, however, be made to point to another location. The declaration
int * const ptr = &joy;
establishes that the pointer ptr can't have its value changed; that is, it can point only to joy . However, it can be used to alter joy .
The prototype
void simple (const char * s);
establishes that after the formal argument s is initialized to whatever value is passed to simple() in a function call, sample() may not alter the value to which s points.
I l @ ve RuBoard |