Given this code:
#include <iostream>
using namespace std;
int main() {
int examplearray[] = {1,2,3};
for (int i = 0; i < 6; i++) {
cout << examplearray[i] << "\t";
}
return 0;
}
I have the following output: 1 2 3 3 4200928 6422336
I am pretty sure this is answered somewhere, but I have been browsing Google for a while and I can't find an explanation for this. I haven't defined a value for the 4th and 5th positions of the array, and I assumed it's value would be 0 or NULL . Why do they have random values?
I noticed this when I was trying to make a code like this:
for(int i = 0; examplearray[i] != 0; /* while it's not empty */i++){
/* do something */
}
How can I do something like I wanted to do on this code?