+ 3

How to find the length or size of an Unknown Multi-dimensional array??

11th Apr 2019, 12:48 PM
Saurabh Gupta
Saurabh Gupta - avatar
5 Réponses
0
I know a better way to find the size of M-D Array!! Here, I wanted to know whether there's any instance variable like <length>!
11th Apr 2019, 1:46 PM
Saurabh Gupta
Saurabh Gupta - avatar
+ 3
Here is an implementation of my idea in python. Read the comments to learn more if you like https://code.sololearn.com/c6z7QTNn1MYp/?ref=app
11th Apr 2019, 1:37 PM
Seniru
Seniru - avatar
+ 2
I ll give you a hint. Create a function which accepts an array. Store a variable called i equal to 0. Then iterates through each element - either it is a normal value or an array. Then check the type of the element and if it is an array then call the function recursively. In this recursive method if the element is a not an array it should increment the value of 1 by 1. And.finally you will have the value of the array
11th Apr 2019, 1:17 PM
Seniru
Seniru - avatar
+ 1
Use sizeof() operator in C. Pass array name as argument...
11th Apr 2019, 12:52 PM
Kuri
Kuri - avatar
+ 1
Saurabh Gupta If you want to know if there exists any instance variable like length, then you ask for it. "How to find the length..." can mean everything and "search for it" would be also an correct answer. ;) I only know Java: yourArray.length;
11th Apr 2019, 10:10 PM
Denise Roßberg
Denise Roßberg - avatar