What is Const Variable in C++

Const values are the static values that can't the change through out the program. The purpose of this is to secure programming and avoid programming mistake which occur due to logic error.

Source Code

#include <iostream>
using namespace std;
int main( )
{
   int const a = 120;
  const int b  = 786;  // DOES'N MATTER YOU DEFINE CONST BEFORE DATA TYPE OR AFTER
  int sum = a+b;
  cout<< " The 1st Const Number is     : "<<a<<endl;
  cout<< " The 2nd Const Number is     : "<<b<<endl;
  cout<<" The SUM OF BOTH NUMBER IS  : "<<sum<<endl;
   }

Output of the Program

Const Variable in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment