网站需要维护吗,python做网站显示表格,设计师服务平台网,嘉兴简单建站常量引用
int main()
{ // int m 10; // 错误#xff0c; 引用必须引一块合法的内存空间#xff08;什么是合法的内存空间#xff0c; 这个10在程序中有内存吗#xff1f;#xff09;const int m 10; //加入const后#xff0c;语法就通过了#xff0c;编译…常量引用
int main()
{ // int m 10; // 错误 引用必须引一块合法的内存空间什么是合法的内存空间 这个10在程序中有内存吗const int m 10; //加入const后语法就通过了编译器优化类似 int temp10; const int m temp; // 可以通过指针来修改 const值int *p (int *)m;*p 1000;cout m endl;return 0;
}常量引用的使用场景
// 引用常用作形参这样不用进程值拷贝const 加在引用前面是保证数据不被修改
void test1(const int a) {
// a 10000; //错误不可以修改cout a endl;
}
void useConstRef() {int a 3;test1(a);
}