title: Where are const objects stored
body: <p>I do understand that functions should not return references to automatic variables.
  However I just wanted to understand where constant objects are stored i.e if it is stored in the memory section along with static global variables .</p>
  
  <p>Here is the code on Visual studio 8 . It looks like const objects are stored as auto variables. Am i assuming things right  or is it implementation specific or does it depend on whether the constructor is trivial  ?</p>
  
  <p>Would be really great if someone could explain why each of these cases behave the way they do.</p>
  
  <pre><code>//here i'm intentionally returning a ptr to local const ptr hope the syntax is right
  
  const char* const* get_const_char_ptr() {
      const char * const ptr = "downontheupside";
      return &amp;ptr;
  }
  
  const int&amp; get_const_int() {        
      const int magic_number = 20;
      return magic_number;
  }
  
  const string&amp; get_const_string() {       
      const string str("superunknown");
      return str;
  }
  
  const string* get_const_string_ptr() {
      const string str("louderthanlove");
      return &amp;str;
  }
  
  int main() {
      //case1
      const int &amp;i = get_const_int();
      cout&lt;&lt;"case1:"&lt;&lt;i&lt;&lt;endl;
  
      //case 2
      const char * const* c =get_const_char_ptr();
      cout&lt;&lt;"case2:"&lt;&lt;*c&lt;&lt;endl;
  
      //case3
      const string &amp;str = get_const_string();
      //this crashes
      //cout&lt;&lt;"case3:"&lt;&lt;str&lt;&lt;endl;
  
      return 1;
  }
  </code></pre>