변수의 메모리 주소를 결정하는 방법을 알아 내려고하고 있습니다. 어느 것이 올바른 사용법인지 모르겠습니다.C++ - 변수의 주소를 올바르게 결정하는 방법?
#include <iostream>
#include <string>
using std::cout;
using std::endl;
void print(std::string *url) {
std::string url_1 = "http://example.com";
cout << url << endl;
cout << "Adress: " << &url << endl;
*url = url_1;
cout << "Adress: " << &url << endl;
}
int main() {
std::string a = "http://google.com";
print(&a);
cout << a << endl;
cout << &a << endl;
return 0;
}
출력 :
0xbfa1ba48
Address: 0xbfa1ba34
Address: 0xbfa1ba34
http://example.com
0xbfa1ba48
변수의 내용을 변경, 메모리 주소 변경뿐만 아니라합니까? 변수의 실제 메모리 주소를 어떻게 얻습니까?
올바른 변수 주소 –
을 인쇄하고 있습니다. 여기에'std :: addressof'를 언급 할 기회가 생길 것이라고 생각했습니다. – chris
사람이 집에서 나가 다른 사람이 이사하면 집 주소가 바뀌나요? –