直接上代码
#include <iostream>
using namespace std;
int main() {
const int a=100;//a不可变
a=20;//会报错
auto b=a;
b=100;//不会报错 说明auto会自动忽略a的const属性
cout<<b<<endl;
return 0;
}
修改后
#include <iostream>
using namespace std;
int main() {
const int a=100;//a不可变
//a=20;//会报错
auto b=a;
b=100;//不会报错 说明auto会自动忽略a的const属性
cout<<b<<endl;
return 0;
}
看输出