In a multidimensional array, is it possible to use the length variable to
measure different dimensions other than the first?
In a multidimensional array, is it possible to use the length variable to measure
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. Length dimensions vary from row to row. You can do
matrix[i].lengthto get the length of rowi. If you know the matrix is square, all the row lengths will equalsmatrix[0].lengthanyways, so it doesn’t matter.If you’re trying to iterate through all elements:
The same principle can be applied for any number of dimensions. For loops, you need 1 nested loop per dimension. For lengths, each bracketed part is actually a new element, so 3d array
arwill yield a 2d array withar[i], 1d withar[i][j], and 0d (single element of the array type) withar[i][j][k]