const keyword in C++ by R4R Team

Const variable:
-const variable are those variable whose value is not changed during the entire execution of program.
-only read only is valid on constant variable.
-If you try to change the value of const variable during run time then it will give an error.

program:

#include < iostream>

using namespace std;
int main()
{
const int i=10;
cout<< i;
return 0;
}


output-

10

-In this program, we create a variable of const type and print value so no error occur, but:
Let change the value of constant variable:

program:

#include < iostream>

using namespace std;
int main()
{
const int i=10;
cout<< i;
i++;
return 0;
}


output-

Error: increament of read-only variable 'i'




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!