C++ 的 &
C++ 的 & 比起 C 語言的提取位置,還多了宣告引用 ( 必須在定義時候就進行初始化 )。
int a = 5;
int &b = a;
std::cout << "a value\t\t" << a << "\n";
std::cout << "a address\t" << &a << "\n";
std::cout << "b value\t\t" << b << "\n";
std::cout << "b address\t" << &b << "\n";
int c = 50;
b = c;
std::cout << "a value\t\t" << a << "\n";
std::cout << "a address\t" << &a << "\n";
std::cout << "b value\t\t" << b << "\n";
std::cout << "b address\t" << &b << "\n";
std::cout << "c value\t\t" << c << "\n";
std::cout << "c address\t" << &c << "\n";
a value 5 a address 0x61ff08 b value 5 b address 0x61ff08 a value 50 a address 0x61ff08 b value 50 b address 0x61ff08 c value 50 c address 0x61ff04
參考資料 :