encyclopegia.org

Jagged array

[[File:Jagged Array Representation.png|thumb|right|alt=numArr = [[1, 2, 3], [4, 5, 6, 7], [8, 9 |Memory layout of a jagged array In computer science, a jagged array, also known as a ragged array or irregular array is an array of arrays of which the member arrays can be of different lengths, 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. Jagged array can be implemented with Iliffe vector data structure in languages such as Java, PHP, Python (multidimensional lists), Ruby, C#.NET, Visual Basic.NET, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode.

[[File:Jagged Array Representation.png|thumb|right|alt=numArr = [[1, 2, 3], [4, 5, 6, 7], [8, 9]]|Memory layout of a jagged array]] In computer science, a jagged array, also known as a ragged array or irregular array is an array of arrays of which the member arrays can be of different lengths, 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. Jagged array can be implemented with Iliffe vector data structure in languages such as Java, PHP, Python (multidimensional lists), Ruby, C#.NET, Visual Basic.NET, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode. ==Examples== In C# and Java jagged arrays can be created with the following code: int[][] c; c = new int[2][]; // creates 2 rows c[0] = new int[5]; // 5 columns for row 0 c[1] = new int[3]; // create 3 columns for row 1 In C and C++, a jagged array can be created (on the stack) using the following code: int jagged_row0[] = {0,1}; int jagged_row1[] = {1,2,3}; int *jagged[] = { jagged_row0, jagged_row1 }; In C/C++, jagged arrays can also be created (on the heap) with an array of pointers: int *jagged[5]; jagged[0] = malloc(sizeof(int) * 10); jagged[1] = malloc(sizeof(int) * 3); In C++/CLI, jagged array can be created with the code: using namespace System; int main() { array ^> ^ Arrayname = gcnew array ^> (4); // array contains 4 //elements return 0; } In Fortran, a jagged array can be created using derived types with allocatable component(s): type :: Jagged_type integer, allocatable :: row(:) end type Jagged_type type(Jagged_type) :: Jagged(3) Jagged(1)%row = [1] Jagged(2)%row = [1,2] Jagged(3)%row = [1,2,3] 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(3)] for i in range(3)] Produces: [[[], [], []], [[], [], []], [[], [], []]] multi_list_5d = [[[] for i in range(5)] for i in range(5)] Produces: [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]] ==See also== Variable-length array Iliffe vector ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Jagged array." encyclopegia.org, 2026, https://encyclopegia.org/wiki/jagged-array. Accessed 24 November 2026.

Chicago

"Jagged array." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/jagged-array.

APA

encyclopegia.org. (2026). Jagged array. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/jagged-array

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Bruce Owen

enwiki · references available

Australia You're Standing In It

enwiki · references available

Autoroutes of Morocco

enwiki · references available

Mesoamerican pyramids

enwiki · references available

Mark A. Lutz

enwiki · references available

Sihuanaba

enwiki · references available

Waldstadion (Frankfurt)

enwiki · references available

Let Love Lead the Way

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1341865964 · 0.5 · snapshot enwiki-001341865964

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.