The Big Master

Constants

In C++, constants are named values that cannot be modified or changed...

In C++, constants are named values that cannot be modified or changed during the execution of a program. They represent fixed values that remain constant throughout the program’s execution.

Constants are useful for representing values that should not be altered, such as mathematical constants, fixed dimensions, configuration settings, or any other value that should remain consistent throughout the program.

   const float PI = 3.14159F; //type const float

The following program is using cons for variable pi

#include <iostream>
using namespace std;
int main()
{
     
     const float	pi = 3.1415 ;
              float  r= 5 , ans  ;
    
    ans = 2 * pi * r ;  // assignment statement  assignment is always performed from right to left 
                        // = is the assignment operator 
     cout << ans  << endl ;	
    return 0;
}
#include <iostream>
using namespace std;
int main()
{
    // program to find the circumference of circle 
    const int x = 10 ; 
    x = x + 5 ;  // will not complile . cannot change const	 
     cout << x   << endl ;	
    return 0;
}