Header Responsive Ads

Constant

difference between constant and variable in c++

In the case of a variable, you can re-store a new value. However, in the case of constant, once a value is stored in it, cannot be changed. This is the difference between variable and constant. 

Constant declaration and initialization

Constant can be declared in two ways:-

Before the main function

#define PI 3.14

Inside main function (C++ const keyword is used)

const int pi=3.14;

C++ Program to use Constant:

c++ const
c++ const

Output:

c++ constant output
c++ const output


Post a Comment

Previous Post Next Post

In Article Ads 1 Before Post

In Article Ads 2 After Post