What is constant and How the constant function or term use in CPP?

Practice # 8

#include<iostream>
using namespace std;
int main(){
    int h=60; //here the veriable value of 'h' is 60.
    cout<<"it is the value of h"<<h<<endl;   
    int h=20; //here's the veriable value of 'h' is 20.
              //here we change the value  of 'h'.
    cout<<"it is the value of h"<<h<<endl;
    /* if we don't want to change the value of the
        variable we uses the constants like this. */
    const float pi=3.14f;
    cout<<"it is the value of pi"<<pi<<endl;
    /*now if we change the value of pi we wil
        get an error from compiler.
        Let Change,*/
    float pi = 3.2f;
    return 0;
}

Comments