First, we need to clarify several terms: const pointer and pointer to output:
A const pointer is a pointer that has a constant worth it. It does not include any hint of "whether it is a constant.
Const char * PCI; // pointer to a constant
Char * const CPI = 0; // constant pointer
Char const * pci2; // still a pointer to a constant
Const char * const CPCI = 0; // constant pointer to a constant.
Char * IP; // common pointer
"C ++ standards allow for the (unconditional) type conversion of the 'increase constant ". For example, we can copy a pointer pointing to a constant to a pointer pointing to a constant. In this way, we can -- of course, we can also do many other things -- pass a very large number pointer pointing to the char type to the strcmp or strlen function in the standard library, although their declaration only accepts pointers to Char constants, intuitively we can understand why: allow pointing to constants to point to constants rather than constants, because we do not lose any constraints in data declaration, of course, we can also understand why reverse conversion is blocked, because we get more permissions when data is declared;
Size_t strlen (const char *);
//...
Int I = strlen (CPI); // No problem parameter transfer
PCI = IP; // No problem with pointer assignment
IP = PCI; // Error
Note that C ++ adopts a conservative opinion on data constants: in fact, this can also be done -- without immediately causing a core dump -- we can modify the data that points to the constant pointer, as long as the data is actually (in the unspecified semantics) not constant ①, or they are constants, but the platform that runs the Code does not allocate data to the read-only Area of the internal memory. In short, the typical use of constants is a stand expression during the design period, and also a system attribute identifier. C ++ seems to force the designer's intent.
========================================================== ==================================
Note:
① Annotation: that is to say, if a pointer to a constant points to a data that itself is not a constant, then this pointer to a constant cannot be used to modify the data, but it does not indicate that this data cannot be modified. → See common errors 6.