I found this occurrence to be rather interesting, let me explain:
When I initialized a int array, I started to wonder how c++ handles an index with a no initialized value. When directly using cout, c++ directly outputs the values as 0. However, when inserting a for loop right afterwards, with the same purpose it instead points to the values inside the memory location, and pretends they were not initialized.
To regenerate this error, copy & paste the code below onto a compiler. Run it once without the for loop, and once with the for loop.
I am just interested to find out why this occurs.
#include <iostream>
using namespace std;
int main() {
int myArray[4];
myArray[2] = 32;
cout << "\n Val 1: "<< myArray[0] << "\n Val 2: "<< myArray[1]<< "\n Val 3: "<< myArray[2]<< "\n Val 4: "<< myArray[3]<< "\n Val 5: "<< myArray[4];
cout <<"\n ----------------------------";
/*
for(int i = 0; i < 5; i++){
cout << "\n Val " << i << ": " << myArray[i];
}
*/
return 0;
}