title: Ampersand in c++ range based for loops
body: <p>Here is the code:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;vector&gt;
  #include &lt;cstdio&gt;
  
  int main(int argc, char *argv[]) {
      const unsigned int max_chars = 100;
      char buffer[max_chars];
      std::cin.getline(buffer, max_chars, '\n');
      unsigned int count = 0;
      for (auto c : buffer) {
          if (c == '\0') {
              break;
          }
          count++;
      }
      std::cout &lt;&lt; "Input: ===========" &lt;&lt; std::endl;
      std::cout &lt;&lt; buffer &lt;&lt; std::endl;
      std::cout &lt;&lt; "Number of chars ==" &lt;&lt; std::endl;
      std::cout &lt;&lt; std::dec &lt;&lt; count &lt;&lt; std::endl;
      std::cout &lt;&lt; "==================" &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>This is adapted from some example code in a c++ text book deliberately dealing with c-style strings, so bear with me. </p>
  
  <p>So I tried two versions of this, one with <code>for (auto c : buffer)</code> and the other with <code>for (auto &amp;c : buffer)</code>. Both seemed to work. The question is, what is the difference then?</p>