浅析C++中的引用 发表于 2018-03-17 更新于 2023-06-27 分类于 C++ 为已定义变量创建别名定义变量时,在变量前加上‘&’符号,就表示定义一个引用。首先声明,引用只是为引用对象创建了别名,而并未开辟新的内存。先看下面一段代码: 1234567double i = 42.0;double &r = i;std::cout << "the value of i is " << i << std::endl;std::cout << "the value of r is " << r << std::endl;std::cout << "the address of i is "<< &i << std::endl;std::cout << "the address of r is " << &r << std::endl; 阅读全文 »