Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9
Because there is no (compile time) error. The compiler doesn't check if you use valid indices/offsets. It's your job to make sure that you don't read/write beyond the borders of an array. If you run the program, there might be a run time error if the OS doesn't allow your program to access memory that doesn't belong to your program. Or you might change another variable of your program without even realizing it: int b = 0; // one int int a[2]; // array with two more ints Here, b might be stored in the memory position right after the last element of array a. In this case, trying to change a[2] (the third element of your array that only has two elements) will directly affect b.
16th May 2019, 9:18 AM
Anna
Anna - avatar