What is const qualifier? Explain with an example.
- The qualifier const can be applied to the declaration of any variable to indicate that its value will not be changed. Once a variable is declared with const qualifier, it no longer remains a variable (i.e. its value can not be changed). A const must be initialized with some value.
- Example :
const TYPE x = 10; //where TYPE is any data type.
const int x = 5; // This will define x as constant with value 5
- Note that once const is defined, its value can not be changed by arithmetic operations or assignment.
What is const qualifier?
const qualifier is used to specify the variable that can’t be change throughout the program. Variable with const qualifier is often named in uppercase.