const的应用
程序员文章站
2022-07-09 21:46:49
...
const的应用
例如:
void main()
{
int a = 10, b = 20;
int *p1 = &a;
*p1 = 100;
p1 = &b;
const int *p2 = &a;//*p不可改变,p可以改变
int const *p3 = &a; //*p不可改变, p可以改变
int * const p4 = &a;//*p可改变,p不可以改变
const int * const p5 = &a;//*p不可改变,p不可以改变
*p2 = 200;
p2 = &b;
*p3 = 200;
p3 = &b;
*p4 = 200;
p4 = &b;
p5 = &b;
*p5 = 200;
}*/
上一篇: C++ const用法
下一篇: C++ 学习记录