If you declare int data[10], what is the index of the last element?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

If you declare int data[10], what is the index of the last element?

Explanation:
Arrays use zero-based indexing, meaning the first element is at index 0. If you declare int data[10], you’ve created 10 elements with indices 0 through 9. The last element is therefore data[9]. Accessing data[10] would go past the end (out of bounds), data[8] would be the second-to-last, and data[0] is the first.

Arrays use zero-based indexing, meaning the first element is at index 0. If you declare int data[10], you’ve created 10 elements with indices 0 through 9. The last element is therefore data[9]. Accessing data[10] would go past the end (out of bounds), data[8] would be the second-to-last, and data[0] is the first.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy