The difference between const char*, char const*, char* const

The weather will be fine on Monday, February 1, 2021 [Do not lament the past, do not waste the present, do not fear the future]



1. const char* and char const* are equivalent

The C++ standard stipulates that constkeywords placed before the type or variable name are equivalent, so const char*and char const*are equivalent.

const char *p;   //same as below
char const *q;  

2. The difference between const char* and char* const

As for const char *psum char* const q, according to the principle of proximity: the former constmodification *pmeans that the content pointed to by the pointer cannot be changed, and the latter constmodification qmeans that the value of the pointer itself cannot be changed.

Guess you like

Origin blog.csdn.net/m0_37433111/article/details/113499638