Which of the following gives the nth element of the Array?
2023
Which of the following gives the nth element of the Array?
- A.
array[n];
- B.
array[n-1];
- C.
array[n+1];
- D.
More than one of the above
- E.
None of the above
Attempted by 1653 students.
Show answer & explanation
Correct answer: B
In most programming languages, arrays use 0-based indexing, meaning the first element is at index 0, the second at index 1, and so on. To access the nth element of an array, you need to use the index (n-1). For example, if n = 3, the third element is accessed using array[2]. Therefore, the correct expression is array[n-1].