+3 votes
in Class 12 by kratos

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

1 Answer

+5 votes
by kratos
 
Best answer

The access modifier 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 whereas the value of the variable can be changed during the program run.

Example:

void main () {

const int a =10;

int b = 20;

a++;

cout<<"a="<<a;

b++;

cout<<"b="<<b;

}

...