Impact of access modifier const over variables.

Q17. Explain the impact of access modifier const over variables. Support your answer with examples.

Ans. If the access modifier const is used before variable’s definition, it modifies its access types, that is, the access of the constant variable is readable only, it can no more be written on to. For instance,

int val = 10;

declares a variable val with initial value 10. However, the value of val can be changed in the program at any time. But, if we modify the above definition of variable as follows:

const int val = 10;

the variable val becomes constant and its value remains 10 throughout the program, it can never be changed during program run.