...

/

Accessing an Out of Bound Index

Accessing an Out of Bound Index

Learn what happens if we access an out of bound index in an array.

C program does not generate a subscript out of range error

In C programs, if the programmer accidentally accesses an index of an array that is out of bound, the compiler does not report a subscript out of range error. The program may, however, generate unpredictable results.

See the code given below!

#include<stdio.h>

int main() {
    int a[] = {3, 60, -5, 7, 11};
    int i;
     for (i = 0; i <= 7; i++){
        printf("%d ", a[i]);
    }
}

Line 4: In the expression, a[ i ], a is the array; whereas, i is known as a subscript. Since a[ ] is a ...