Why the array is giving me random values while printing the elements of array which does not exits?

Viewed 26

here's the image of that program

While I tried to print the values of array suppose of length x, its prints correctly but when I tried to print the array with different length rather than predefined length then its giving random values ... how .. ?

1 Answers

Accessing an array out of bounds* will give undefined behavior. It will compile and run, but the results are not predictable.

  • Arrays in C are indexed starting at 0. An array of nine elements has a maximum index of 8. You have accessed elements 9 and 10.
Related