1) Define constant
2) Define constant pointer
const int* p =&n
- Can not modify the contents of the constant pointer
- It is not possible to assign a constant pointer to a non-const pointer, and vice versa, but it can also be coerced (better not)
- The function parameter is a constant pointer to avoid accidentally modifying the content pointed to by the parameter pointer within the function. For example
strcpy(p,"this")
, if p is a parameter, the content pointed to by p is modified.int* const p
It is not possible to modify the address pointed to by the pointer
3) Define often quoted
The first week of learning: const keyword
Guess you like
Origin blog.csdn.net/ZmJ6666/article/details/108548165
Recommended
Ranking