Horje
Types of Arrays

There are majorly three types of arrays

There are majorly three types of arrays:

  1. One-dimensional array (1-D arrays)
  2. Two-dimensional (2D) array
  3. Three-dimensional array

1. One-dimensional array (1-D arrays):

You can imagine a 1d array as a row, where elements are stored one after another.
 

1D array

1D array

Syntax for Declaration of Single Dimensional Array

Below is the syntax to declare the single-dimensional array

data_type array_name[array_size];

where,

  • data_type: is a type of data of each array block.
  • array_name: is the name of the array using which we can refer to it.
  • array_size: is the number of blocks of memory array going to have.

For Example

int nums[5];

2. Two-dimensional (2D) array:

Multidimensional arrays can be considered as an array of arrays or as a matrix consisting of rows and columns.
 

2D array

2D array

Syntax for Declaration of Two-Dimensional Array

Below is the syntax to declare the Two-dimensional array

data_type array_name[sizeof_1st_dimension][sizeof_2nd_dimension];

where,

  • data_type: is a type of data of each array block.
  • array_name: is the name of the array using which we can refer to it.
  • sizeof_dimension: is the number of blocks of memory array going to have in the corresponding dimension.

For Example

int nums[5][10];

3. Three-dimensional array:

A 3-D Multidimensional array contains three dimensions, so it can be considered an array of two-dimensional arrays.
 

3D array

3D array

Syntax for Declaration of Three-Dimensional Array

Below is the syntax to declare the Three-dimensional array

data_type array_name[sizeof_1st_dimension][sizeof_2nd_dimension][sizeof_3rd_dimension];

where,

  • data_type: is a type of data of each array block.
  • array_name: is the name of the array using which we can refer to it.
  • sizeof_dimension: is the number of blocks of memory array going to have in the corresponding dimension.

For Example

int nums[5][10][2];



Reffered: https://www.geeksforgeeks.org


Arrays

Related
Why Array Data Structures is needed? Why Array Data Structures is needed?
Array Representation in Data Structures Array Representation in Data Structures
Maximum illumination duration with reducing candles Maximum illumination duration with reducing candles
Construction of multiple AP Arrays Construction of multiple AP Arrays
Lemonade Stand Change challenge Lemonade Stand Change challenge

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12