I have two C++ codes in which the one has an global int array while the other code has a local array whose length is determined by user input (so at runtime). Both arrays are not explicitly initialized.
#include <iostream>
using namespace std;
int M = 1000;
int a[M];
int main() {
  for(int i = 0; i < M; i++)
    cout << a[i];
  cout << endl; 
}
#include <iostream>
using namespace std;
int main() {
  int M;
  cin >> M;
  int a[M];
  for(int i = 0; i < M; i++)
    cout << a[i];
  cout << endl; 
}
I observed that the global array is filled with zeros, while the local array (whose length is determined at runtime) is not filled with zeros and instead filled with a random numbers (but same at a time). I used the g++ compiler.
What is this behavior? Does C++ standard define this behavior?
 
     
    