[array]: Statement, I don't understand

My arrays are in 6 positions? right

why notes[60] don't failed?
and why notes[66] run failed?

IDE: NetBeans 7.3.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int main(void) {
    float notes[6];
    int chapters[6];
    short Class[6];
    notes[60]=100.0;
    chapters[10]=19;
    Class[149]=149;
    
   /*
    notes[66]=12.5; --- run failed
    chapters[72]=19 -- run failed
    Class[150]=150; -- run failed
   */
   cout << notes[60]<<endl;
   cout << chapters[10]<<endl;
   cout << Class[149]<<endl;
   return 0;
} 
Last edited on
Accessing out of bounds array subscripts results in undefined behaviour. Sometimes it may fail, sometimes it may not. In any event, it should be avoided.
Topic archived. No new replies allowed.