title: C++ array of fixed size getting garbage values
body: <p>I was trying to rotate a string circularly by 1 shift. Here's the simple code:</p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main() {
    string s = "1010";
    char a[s.length()];
    for (int i = 0; i &lt; s.length() - 1; i++) {
      a[i] = s[i+1];
    }
    a[s.length()-1] = s[0];
    std::cout &lt;&lt; a &lt;&lt; '\n';
    std::cout &lt;&lt; strlen(a) &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>When I run this code, I get the following output:</p>
  
  <pre><code>aditya@aditya-Inspiron-3558:~/miscCodes$ ./a.out 
  0101�
  6
  </code></pre>
  
  <p>How's my array's length is changing?
  And due to garbage values?</p>