- 修饰变量,表示该变量为常变量,可代替宏。
- 修饰指针,表示该指针,表示该指针指向常量或者该指针为常指针。
- 修饰引用,常用于修饰函数形参,变成常引用,可以避免重复拷贝和函数对值的修改。
详细说明:https://blog.csdn.net/itworld123/article/details/78967080
- 修饰函数,表示该函数不能对类成员变量进行修改。
- 修饰函数返回值,如下所示:
const int func(); // 返回常变量。 const int i = func();
const int *func(); // 返回的指针指向常量。 const int *p = func();
int * const func(); // 返回的常指针。 int * const p = func();
(SAW:Game Over!)