1 Use of the const
In C programs, the use of const mainly defines constants, modifier function parameters, and modifier function return values.
In a C + + program, it can also modify the definition body of a function, defining a member function in a class as a constant state function, that is, the data members in the class are not changed.
In the const member function, you can modify the member variables of a class after the member variable name is decorated with mutable.
The const-modified items are protected against accidental changes and can improve the robustness of the program.
2 Extensions
The const in C means "an ordinary constant that cannot be changed." In C, it always takes up memory, and its name is the global character. The C compiler cannot treat Const as a constant during compilation.
Const bufsize;
In C + + it is not right, and the C compiler takes it as a declaration that indicates that there is memory allocation somewhere else.
c The default const is externally connected, and the C + + default const is internally connected.
In C + +, you can use extern to change an internal connection to an external connection.
Eg:extern Const bufsize; Declaration only. can also be used in C.
Using the qualifier const in the C language is not very useful, even in constant expressions (which must be evaluated during compilation) to use a named value, and using const is not very useful. C Forces programmers to use # define in preprocessing.
C + + Programming-const