Skip to content

Types of Array

Based on Dimensional

One Dimensional Array

  • A basic array where elements are arranged in a single row or a single column.
  • Elements are accessed using a single index.
  • Example: int numbers[5]; creates an array capable of holding five integers.

Multi Dimensional Array

  • An array containing one or more arrays as its elements.
  • Elements are arranged in rows and columns (two-dimensional), or in multiple dimensions (three-dimensional or higher).
  • Example: int matrix[3][3]; creates a two-dimensional array representing a 3x3 matrix.

Based on Size

Static Array

  • Fixed Size: Size is determined at compile time and remains constant throughout program execution.
  • Memory Allocation: Occupying a fixed amount of memory, allocated on the stack, fast access but limited space.
  • Cannot Resize: Once declared, the size cannot be changed during runtime.

Dynamic Array

  • Size Flexibility: Size can be adjusted during runtime.
  • Memory Allocation: Allowing for flexibility in memory usage, allocated on the heap, more flexible but slower access.
  • Resizable: The size can be changed as needed during program execution.
  • Often used when the size of the array is not known beforehand or needs to change dynamically based on program logic.