C++(常量引用)

    科技2024-05-16  77

    #include"stdafx.h" #include <iostream> using namespace std; //此处返回局部变量引用 void test(const int& b) { // b=1000;//常量引用能够防止修改b的值 cout<<"b="<<b<<endl; } /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int a=10; //int&rel=10;//引用需要一块合法内存空间,故此处错误 const int& rel=100;//常量引用,此处相当于 int temp=10;int& rel=temp; test(a); system("pause"); return 0; }
    Processed: 0.020, SQL: 8