二级考试C++基础:C++中CONST的用法
const char *const * keywords
const char const * keywords
const char *const keywords
const char const keywords
下面总结一下CONST的用法。const主要是为了程序的强健型,削减程序出错。考试,大提示const指针和引用一般用在函数的参数中。最根本的用法如下:
// a的内容不变,a只能是100也就是声明一个int类型的常量(#define b =100)
const int a=100;
int const b=100; //和上面作用一样
//下面两句话一样
const int b=100;
int const b=100;
const放在*左侧修饰的是指针的内容,const放在*右侧修饰的是指针本身。如下:
const int* pa = //指针指向的内容为常量(就是a的值不变)
int const *a = //指针指向的内容为常量(就是b的值不变)*p=3//error ...


雷达卡


京公网安备 11010802022788号







