Jagged array


In computer science, a ragged array, also known as a jagged array, is an array of arrays of which the member arrays can be of different sizes and producing rows of jagged edges when visualized as output. In contrast, two-dimensional arrays are always rectangular so jagged arrays should not be confused with multidimensional arrays, but the former is often used to emulate the latter.
Arrays of arrays in languages such as Java, PHP, Python, Ruby, C#.Net, Visual Basic.NET, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode are implemented as Iliffe vectors.

Examples

In C# and Java jagged arrays can be created with the following code:

intc;
c = new int; // creates 2 rows
c = new int; // 5 columns for row 0
c = new int; // create 3 columns for row 1

In C and C++, a jagged array can be created using the following code:

int jagged_row0 = ;
int jagged_row1 = ;
int *jagged = ;

In C/C++, jagged arrays can also be created with an array of pointers:

int *jagged;
jagged = malloc;
jagged = malloc;

In C++/CLI, jagged array can be created with the code:

using namespace System;
int main

In Python, jagged arrays are not native but one can use list comprehensions to create a multi-dimensional list which supports any dimensional matrix:

multi_list_3d = for i in range] for i in range]
  1. Produces: , , , , , ,
multi_list_5d = for i in range] for i in range]
  1. Produces: , , , , , , , , , , , , , , , , , , , ,