EDIT: ^^^ "duplicate" doesn't mention arrays at all
EDIT2: Hold on that's in C, not C++, isn't there a difference between 2 languages ?!
This question has been bugging me for some time lately. Google search revealed nothing.
So I have this snippet of example C++ code:
int factors[100]; /* note this is not initialized */
int number = /* less than 100 */ 10;
for (int i = 0; i < number; i ++) {
factors[i] = 1;
}
for (int i = 0; i < 100; i ++) {
std::cout << factors[i] << std::endl;
}
The output is (scroll down to bottom)
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1640775680
32767
114023525
624860211
174064279
236792104
-1027703263
587262357
1599638600
32767
17
0
1
0
6778984
1
1640935824
32767
1599638352
32767
1640780406
32767
1599638384
32767
1599638384
32767
1
0
1599638408
32767
6778880
1
1640776264
32767
1599638424
32767
0
0
0
0
0
0
0
0
0
0
Why isn't it either ten 1s or ten 1s and ninety 0s, and why are there so many seemingly random (maybe related to powers of 2?) numbers? I think it may have something to do with memory allocation or something but I'm just a beginner and I've not gotten into this stuff yet.