Iterating over array of chars in C : <p>If I iterate over an array of chars using a pointer and declared this way:</p>

<pre><code>char my_ary[3] = { 'A', 'B', 'C' };
char *my_p = my_ary;
while(*my_p){
  printf("value of pointer is %c\n", *my_p);
  my_p++;
}
</code></pre>

<p>I get the values along with some garbage:</p>

<pre><code>value of pointer is A
value of pointer is B
value of pointer is C
value of pointer is �
value of pointer is �
value of pointer is u
value of pointer is �
value of pointer is �
value of pointer is 
</code></pre>

<p>If on the other hand I declare the array as static, I don't get the garbage:</p>

<pre><code>static char my_ary[3] = { 'A', 'B', 'C' };
char *my_p = my_ary;
while(*my_p){
  printf("value of pointer is %c\n", *my_p);
  my_p++;
}

value of pointer is A
value of pointer is B
value of pointer is C
</code></pre>

<p>Why is the static keyword affecting this particular case?</p>
