Concept of constant variable.

Q8. Explain with example the concept of constant variable.

Ans. The keyword const can be added to the declaration of an object to make that object a constant rather than a variable. Thus, the value of the named constant cannot be altered during the program run. The general form of constant declaration is as follows:

const type name = value;

where const is the keyword that must be used for declaring a constant, type is any valid C++ data type, name is the name of the constant and value is the constant value of the data type type. For instance,

const int upperage = 50;

declares a constant named a upperage of type integer that holds value 50;

a constant must be initialized at the time of declaration. If you give only const in place of const int, it means the same.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: