The const Member Functions
The member functions of a class can also be declared as constant using const keyword. The constant functions cannot modify any data in the class. The const keyword is suffixed to the function prototype as well as in function definition. If these functions attempt to change the data, compiler will generate an error message.
8.30 Write a program to declare const member function and attempt any operation within it.
Explanation: In the above program, the class A is declared with one member variable (c) and one constant member function add(). The add() function is invoked with two integers. The constant member function cannot perform any operation. Hence, the expression c=a+b will generate an error. The expression a+b is valid and cannot alter any value. The result obtained from the equation a+b is displayed using CPU register.