const有一种用法,是在函数声明之后,加上const,这么做的作用是使该函数无法改变这个函数外部的变量,但是该函数内的不受限制,对于该函数内部,外部的变量都被加上了const修饰符。
代码:
void pl(int &a){a++;}
int t =0;
void f_const(){
pl(t);
int k=3;
pl(k);
}
int main(){
f_const();
return 0;
}
编译不通过,报错无法将const int 转为int& ,注释掉pl(t);编译通过