Programmingoneonone is known for sharing best programming knowledge.

constant arguments in c++ programming

In this post, you will learn about the constant arguments in c++ programming and learn how and why we use the constant arguments in programming.

constant arguments in c++ programming, learn c++ programming
learn c++ programming

constant argument:

the argument which value is constant and we cannot modify the value of the arguments is called constant arguments.

use the const keyword to make a variable or argument constant.

Example:
              const int a;

now a is the constant variable. so we cannot modify the value of variable a.

a++; // not possible due to constant keyword.
a=a+10; // not possible due to constant keyword.

An example program using the constant keyword 

#include<iostream>

int main()
{
  const int a=10;
   
  std::cout<<"\n Value of a is: "<<a;

  a=a+10;
  std::cout<<"\n Value of a is: "<<a; //it's show error because o constant value

  return 0;

}

Note:  In the above example this program shows an error because we cannot change the value of a. we make the value of a constant we cannot change or increment the value of a.

to remove the error just remove the a=a+10; line. and then run the program and you will get the output.

"Please share this knowledge as much possible as you can, also comment me your queries and questions related to this topic in the section given below."

No comments:

Post a Comment