C++ Constants

C++ constants are fixed values that can not be altered at any stage of the program. Const literal is used to make any variable a constant or read-only.

Syntax

const data_type variable_name = value;

For Example

const float PI = 3.14; PI value is always fixed
PI=45.00; If we change its value 
cout<<PI; 7 Shows [Error] assignment of read-only variable 'PI'

Note

We can use constants (const) for the fixed value variables whose value remains the same throughout the program.


Recommended Article

C++ program to find the area and perimeter of a rectangle

C++ program to count positive, negative, and zeros

Scroll to Top