title: Printf different objects from same array gives unexpected results?
body: <p>I've managed to narrow down a problem with my code to this:</p>
  
  <pre><code>class A{
      private:
          int a;
      public:
          A(){};
          A(int i){a=i;};
          const char* str(){
              std::stringstream ss;
              ss &lt;&lt; this &lt;&lt; "-&gt;" &lt;&lt; a;
              return ss.str().c_str();
          };
  };
  int main(){
      A test[2] = {A(42), A(99)};
  
      printf("%s,%s\n",test[0].str(),test[1].str());
      printf("%s,",test[0].str());
      printf("%s",test[1].str());
      return 0;
  }
  </code></pre>
  
  <p>Which, quite surprisingly, prints this:</p>
  
  <pre><code>0x7ffff5b574a0-&gt;42,0x7ffff5b574a0-&gt;42
  0x7ffff5b574a0-&gt;42,0x7ffff5b574a4-&gt;99
  </code></pre>
  
  <p>Why does this happen? Is it printf glitching? Please enlighten me.</p>