2D array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

2D array

Why do we need to specify the column of the two dimensional array while we can leave the row unspecified?

8th Jan 2019, 2:40 PM
Adugna.T
Adugna.T - avatar
2 Answers
0
You can't, as far as I'm concerned. Can you show me an example of what you are referring to?
8th Jan 2019, 3:36 PM
Rain
Rain - avatar
0
If the length of rows (no. of columns) is not specified, the compiler can't determine where exactly the next row is going to begin. ex: int Arr[2] [3] which is nothing but array having two 1-D arrays of 3 elements each if you decide to pass this array as an argument to any function you can skip left most dimension. This is applicable to all multi dimensional arrays. You must specify all but the left most dimension. ex: int Arr[] [3] [4] why can you leave row unspecified? just passing array name to function returns pointer to the first element of the array, from there you can traverse through the 2-D array if you know number of columns in the array. Hence it's optional to specify row dimension.
9th Jan 2019, 6:34 AM
Nithin
Nithin - avatar