Discussion
The first index number in an array starts with................and the index number of an array of size n will be :
Answer: A
The first index is 0 and the last is n - 1, so the answer is 0, n - 1.
In C and C++, an array index is an offset from the start of the array. The first element is at offset 0, so it is a[0]. An array of size n therefore has elements a[0] to a[n-1], which is n elements in all.
Starting at 1 is the convention of languages such as Fortran, not C. Using n as the last index reads one element past the end of the array, a classic off-by-one error that causes undefined behaviour.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development