141k views
3 votes
What happens when the programmer tries to access an array cell whose index is greater than or equal to its logical size?

User VictorT
by
3.3k points

1 Answer

0 votes

Answer:

When a programmer tries to access an item in an array cell whose index is greater than or equal to the array's logical size, this data element or item is garbage. This means that currently, the item is not the part of the program's useful data. Garbage contains objects or data which will not be used by a program running on it. So the value returned could be either of the two:

  • Value would be an arbitrary or random number if it is an array of numbers. Arbitrary means that the value is not predefined or specified in advance.
  • Value returned would be null if it is an array of objects.

User MHewison
by
4.2k points