Discussion
A two dimensional array B of 4 byte elements has 10 columns and lower bounds of zero. In row major order, what offset does B[2][3] occupy?
Answer: C
Row-major order lays each row out contiguously, so the linear index counts whole rows first: \[ \text{index} = i \times n_{cols} + j = 2 \times 10 + 3 = 23 \] \[ \text{offset} = 23 \times 4 = 92 \ \text{bytes} \] Column-major order would compute \( j \times n_{rows} + i \) instead, which is why the same subscript addresses different memory in Fortran and in C.
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