1 #include <iostream>
2 #include <string>
3
4 using namespace std;
5
6 string version(string &a, const string &b);
7
8 int main(void)
9 {
10 string input = "I love you.";
11 cout << "input address: " << &input << endl;
12 const char* b = "***";
13 cout << "i b address: " << &b << endl;
14
15 version(input, b);
16
17 return 0;
18 }
19
20 string version(string &a, const string &b)
21 {
22 using namespace std;
23 cout << "a address: " << &a << endl;
24 cout << "b address: " << &b << endl;
25 return a;//没有这句会产生内存错误。返回引用。
26 }
27 /************************************
28 * input address: 0x7ffe09a647f0
29 * i b address: 0x7ffe09a647e8
30 * a address: 0x7ffe09a647f0
31 * b address: 0x7ffe09a64840
32 * **********************************/