#include <iostream>
using namespace std;
int main()
{
int a[6];
for(int i=0;i<6;i++)
{
cout <<a[i]<<" ";
}
cout << endl;
return 0;
}
I have a simple piece of c++ code as above. The array is created on the stack and not initialized.
I got the following output: 0 0 0 0 1569540800 32767.
I don't really understand where the last two numbers come from. More specifically,I don't know what are the values in a[4] and a[5]. And I tried to run the program multiple times. a[4] is changing every time while a[5] is always 32767.
I also tried to create an uninitialized array with length of 4 and 8. In these cases, the output is all zeros.
I understand that an array must be initialized. I ran into this situation when I played around with c++ array. I just want to have a deeper understanding of what's going on in memory.
My environment is clang++ on a Mac.