title: Class type for stack allocation. Why the address for both ID instances are the same?
body: <pre><code>class ID
  {
  public:
      ID(const std::string&amp; name) :
          name_(name) {}
  
      // explicit copy constructor as my first solution but gave me same address
      ID(const ID&amp; other)
      { name_ = other.getName(); } 
  
      std::string getName() const
      { return name_; }
  
  private:
      std::string name_;
  };
  
  ID createID(const std::string&amp; name)
  {
      ID id(name); // new stack allocation for id
      std::cout &lt;&lt; "ID addr: " &lt;&lt; &amp;id &lt;&lt; "\n";
      return id;
  }
  
  int main()
  {
      ID my_id = createID("John"); // new stack allocation for my_id
      std::cout &lt;&lt; "my_id addr: " &lt;&lt; &amp;my_id &lt;&lt; "\n";
      std::cout &lt;&lt; my_id.getName() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Platform: Ubuntu terminal (Windows' Ubuntu Subsystem)</p>
  
  <p>Compilation: g++ file.cpp</p>
  
  <p>Output: "Same address between IDs"</p>
  
  <p>Shouldn't the output provided different stack address?</p>
  
  <p>I tried replicating this with primitive integer (instead of ID class type) and it outputs different address for different instances.</p>
  
  <pre><code>int func(int i)
  {
          int j = i;
          std::cout &lt;&lt; "i addr: " &lt;&lt; &amp;i &lt;&lt; std::endl;
          std::cout &lt;&lt; "j addr: " &lt;&lt; &amp;j &lt;&lt; std::endl;
          return i;
  }
  
  int main()
  {
          int x = 10;
  
          std::cout &lt;&lt; "X addr: " &lt;&lt; &amp;x &lt;&lt; std::endl;
          int y = func(x);
          std::cout &lt;&lt; "Y addr: " &lt;&lt; &amp;y &lt;&lt; std::endl;
  }
  </code></pre>