用于修饰变量,表示该变量的值不能被修改。
const int num = 10;// num = 20; // 错误,不能修改const修饰的变量的值用于修饰指针,表示指针指向的值不能被修改。
const int *ptr;int num = 10;ptr = #// *ptr = 20; // 错误,不能修改const修饰的指针指向的值用于修饰函数参数,表示在函数内部不能修改该参数的值。
void func(const int num) { // num = 20; // 错误,不能修改const修饰的函数参数}用于修饰函数返回值,表示函数返回的值不能被修改。
const int func() { return 10;}// func() = 20; // 错误,不能修改const修饰的函数返回值用于修饰函数,表示函数不会修改任何数据。
int add(const int a, const int b) { return a + b;} 

