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?

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.