title: C++ - How to correctly determine the address of a variable?
body: <p>I'm trying to figure out how to determine the memory address of a variable. I do not know which is the correct way to use.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using std::cout;
  using std::endl;
  void print(std::string *url) {
      std::string url_1 = "http://example.com";
      cout &lt;&lt; url &lt;&lt; endl;
      cout &lt;&lt; "Adress: " &lt;&lt; &amp;url &lt;&lt; endl;
      *url = url_1;
      cout &lt;&lt; "Adress: " &lt;&lt; &amp;url &lt;&lt; endl;
  }
  int main() {
  
    std::string a = "http://google.com";
    print(&amp;a);
    cout &lt;&lt; a &lt;&lt; endl;
    cout &lt;&lt; &amp;a &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0xbfa1ba48
  Address: 0xbfa1ba34
  Address: 0xbfa1ba34
  http://example.com
  0xbfa1ba48
  </code></pre>
  
  <p>When altering the contents of a variable, does the memory address change as well? How do you get the real memory address of a variable?</p>