Jagged Array or Array of Arrays in C with Examples
The array can be of different sizes.it is producing rows of jagged edges.
when visualized as output. a jagged array is an array of array. The difference between a rectangular array and a jagged array is rectangular array is one object and
two dimensions or each element are integers but in the case of a jagged array, all elements are the different lengths and different sizes.
create the jagged array in C using pointers
int *const jagged[] = {
(int []) { 0, 1 },
(int []) { 1, 2, 3 }
};
We are create small example of jagged array-:
we want to always size of array sizes :
int jagged[][3] = { {2,4}, {1,2,3} };
int size = sizeof(jagged);
printf("size=%d\n", size);
int* p = (void*)jagged;
for (int i=0;i<(size/(int)sizeof(int));i++)
{
printf("%d=%d\n", i, *p++);
}
output:
size=24
0=2
1=4
2=0
3=1
4=2
5=3
----------------------------------------------Example of c#---------------------------------------------
We are also creating a jagged array program in c#.let's see the example of the jagged array.
Output:
Element(0): 1 3 5 7 9
Element(1): 2 4 6 8

Comments