Const refers to a compile-time constant.
Keywordconst allows the code to determine whether a variable can be altered.
With const, you can prevent changes to variables or pointers, and more importantly, a const reference prevents changes to the referenced object .
In general, in C, I habitually use define for the definition of some constants, whereas in C + + it is better to use const instead.
For embedded programs, the use of const is quite subtle, and it is important that the variables are stored in ROM after being modified by Const.
With regard to the use of const pointers, there is no meaning in the text explanation, directly refer to the following code and gaze:
#include <iostream>//const//-A compile time constraint that an object can is not modifiedint main () {const int i = 1;int a = 0;const int *p1 = &i;///< data is const and pointer is notint* const P2 = &a; < pointer p2 itself is a const, but the data P2 point to was not const//int* const P3 = &i; < illegal, cannot convert from ' const int * ' to ' int *const ' int const* p4 = p1; < If Const is on the left of *,data is const///< if cosnt are on the right of *,pointer are constconst int* const p 5 = &i; <the data and the pointer are both Constreturn 0;}
Duanxx C + + Learning: Const pointers for specific explanations