title: the difference between for(char& c : s) and for(char c : s)?
body: <p>This is a problem on leetcode</p>
  
  <blockquote>
    <p>Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.</p>
    
    <p>The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.</p>
  </blockquote>
  
  <p>And this is a solution:</p>
  
  <pre><code>class Solution {
  public:
      bool isValid(string s) {
          stack&lt;char&gt; paren;
          for (char&amp; c : s) {
              switch (c) {
                  case '(': 
                  case '{': 
                  case '[': paren.push(c); break;
                  case ')': if (paren.empty() || paren.top()!='(') return false; else paren.pop(); break;
                  case '}': if (paren.empty() || paren.top()!='{') return false; else paren.pop(); break;
                  case ']': if (paren.empty() || paren.top()!='[') return false; else paren.pop(); break;
                  default: ; // pass
              }
          }
          return paren.empty() ;
      }
  };
  </code></pre>
  
  <p>This is another solution:</p>
  
  <pre><code>class Solution {
  public:
      bool isValid(string s) {
          stack&lt;char&gt; paren;
          for (char c : s) {
              switch (c) {
                  case '(': 
                  case '{': 
                  case '[': paren.push(c); break;
                  case ')': if (paren.empty() || paren.top()!='(') return false; else paren.pop(); break;
                  case '}': if (paren.empty() || paren.top()!='{') return false; else paren.pop(); break;
                  case ']': if (paren.empty() || paren.top()!='[') return false; else paren.pop(); break;
                  default: ; // pass
              }
          }
          return paren.empty() ;
      }
  };
  </code></pre>
  
  <p>The only difference between two solution is </p>
  
  <pre><code>for (char&amp; c : s) 
  </code></pre>
  
  <p>in the first solution and</p>
  
  <pre><code>for (char c : s) 
  </code></pre>
  
  <p>in the second solution.
  However, the first solution only take 3ms and the second takes 6ms.
  So why the first solution is faster than the second solution?</p>