Search code examples
oopprocedural-programming

Why do we use multiple dimensional arrays?


I have an understanding about how multiple dimensional arrays work and how to use them except for one thing, In what situation would we need to use them and why?


Solution

  • Basically multi dimension arrays are used if you want to put arrays inside an array.

    Say you got 10 students and each writes 3 tests. You can create an array like: arr_name[10][3]

    So, calling arr_name[0][0] gives you the result of student 1 on lesson 1. Calling arr_name[5][2] gives you the result of student 6 on test 3.

    You can do this with a 30 position array, but the multi dimension is:

    1) easier to understand

    2) easier to debug.