The values of some variable may be required to remain constant through-out the program. We can do this by using the qualifier const at the time of initialization.
Example:
Const int class_size = 40;
The const data type qualifier tells the compiler that the value of the int variable class_size may not be modified in the program.
Volatile Variable
A volatile variable is the one whose values may be changed at any time by some external sources.
Example:
volatile int num;
The value of data may be altered by some external factor, even if it does not appear on the left hand side of the assignment statement. When we declare a variable as volatile the compiler will examine the value of the variable each time it is encountered to see if an external factor has changed the value.
Wednesday, May 13, 2009
Declaring Variable as Constant
Labels:
c training,
c++ training,
character set,
download source code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment