I cannot remember what the specific c++ project is, but what impressed me most is the definition of constant pointer.
If we want to define a pointer which the address content is able to change, we can‘t use char const * p, for example:
- char const *p;
- p=str;
- *p=‘n‘;
we will get an error message:
错误: 向只读位置‘*p’赋值
char * const p; //define a pointer which the address is unable to change
char const * p;//define a pointer which the address content is unable to change
const char *p; //the same as char const *p
时间: 2024-10-03 13:09:55