Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the definition of a "true" multidimensional array and what languages support them?

Most of the programming books I have ever read, have the following line:

"X language does not support true multidimensional arrays, but you can simulate (approximate) them with arrays of arrays."

Since most of my experience has been with C-based languages, i.e. C++, Java, JavaScript, php, etc., I'm not sure of what a "true" multidimensional array is.

What is the definition of a true multidimensional array and what languages support it? Also, please show an example of a true multidimensional array in code if possible.

like image 406
Jesse Good Avatar asked Nov 18 '11 04:11

Jesse Good


People also ask

What is true about the multidimensional array in C language?

Single dimensional array only stores single data or information like marks of the student. But in some cases, you have to store complex data which have rows and columns. So, a single dimensional array can't have this type of feature.

How do you define a multidimensional array?

A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows and columns. Each element is defined by two subscripts, the row index and the column index.

What is multidimensional array explain with example?

A multi-dimensional array is an array with more than one level or dimension. For example, a 2D array, or two-dimensional array, is an array of arrays, meaning it is a matrix of rows and columns (think of a table). A 3D array adds another dimension, turning it into an array of arrays of arrays.

Can C language handle multidimensional arrays?

In C programming, you can create an array of arrays. These arrays are known as multidimensional arrays. For example, float x[3][4];


1 Answers

C# supports both true multi-dimensional arrays, and "jagged" arrays (array of arrays) which can be a replacement.

// jagged array
string[][] jagged = new string[12][7];

// multidimensional array
string[,] multi = new string[12,7];

Jagged arrays are generally considered better since they can do everything a multi-dimensional array can do and more. In a jagged array you can have each sub-array be a different size, whereas you cannot do that in a multi-dimensional array. There is even a Code Analysis rule to this effect (http://msdn.microsoft.com/en-us/library/ms182277.aspx)

like image 185
Dylan Smith Avatar answered Nov 05 '22 03:11

Dylan Smith