In the C language we work with symbolic constants in the way defined by the # define macro. In C + + there is a better way to handle symbolic constants, which is to use the Const keyword to modify the declaration and initialization of variables. The benefit of this method of handling constants is self-evident: if the program needs to use the same value in multiple places, we might as well define the value as a constant, so that when you need to modify the value, you just have to modify the constant to save a lot of trouble.
In addition to the macro definition of C language, the advantage of the Const qualifier is: 1, the ability to explicitly specify the type, 2, you can use the scope of C + + to define the definition of a specific function or file. The following code:
#include <iostream>
#include <string>
#define Mon ' C '
#define MOS 1.5
#define MOM "ch"
#define MAX 100000000
int main ()
{
Using Std::cout;
Using Std::endl;
Using Std::string;
const int Month = 12;
const char char = ' C ';
string Str = "Hello";
cout<<month<<endl;
cout<<str<<endl;
cout<<char<<endl;
cout<<mon<<endl<<max<<endl;
return 0;
}
C++const Qualifier