Why do we use multiple dimensional arrays?

thechrishaddad picture thechrishaddad · Jul 7, 2013 · Viewed 13.4k times · Source

I am learning about 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 these? and why?

Answer

Zen 8000k picture Zen 8000k · Jul 7, 2013

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.