2
int main (){

    int number[5];

    number[0]=45;
    number[1]=12;
    number[2]=555;
    number[5]=89;
    number[6]=46; 

    printf("%d",number[6]); 
}

As we know, we're not supposed to access array out-of-bounds. Here, how the number[6] can be executable?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261

2 Answers2

4

how the number[6] can be executable

I'll humbly suggest to use "accessible" instead of "executable"

  • Point 1. Both the number[5] and number[6] are out of bound. Remember, C uses 0 based index for arrays.

  • Point 2. Accessing out of bound memory causes undefined behaviour. This includes all sorts of strange behaviours.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
2

Going outside the limits of any array leads to undefined behavior

You have declared number to be an array of size 5. And you are trying to use number[5] and number[6]. This is an undefined behavior.

Raman
  • 2,735
  • 1
  • 26
  • 46