I've written a blog before. Introduction to const Usage: const usage in C + +
Today I found a busy point, I hereby add.
As we know, there are three cases in which the general const modifies pointers.
<span style= "FONT-SIZE:18PX;" >const int *p;</span>
This means that P points to a const variable of type int, but the pointer itself is not a const.
int a = 0;int *const p = &a;
This condition indicates that the pointer is const and cannot point to additional data once initialized.
int a = 0;const int *const p = &a;
This situation means that pointers and pointers to objects are const.
But here's the problem.
If you use a TypeDef, such as this
typedef int *INTP;CONST INTP p;
So what type of pointer is P?
My answer without hesitation is a normal pointer, but an int variable that points to Const.
In reality, however, p is a const pointer, and the variable it points to is not a const variable. Because INTP is a data type, an int pointer type, const modifies the pointer type, and therefore is a const pointer, the two lines above are equivalent to
int *const p;
Const usage in C + + (2)