Types
This section provides an overview of the different types of arrays and their usage in programming.
-
One-Dimensional Arrays: These are simple arrays that store elements in a single line. For example, an array of integers:
[1, 2, 3, 4]. -
Multi-Dimensional Arrays: These arrays extend the concept of a one-dimensional array to multiple dimensions. A common example is a 2D array, which can be visualized as a matrix:
[[1, 2], [3, 4], [5, 6]].
Example (One-Dimensional Array in Python):
# Creating a simple array (list in Python)
arr = [1, 2, 3, 4, 5]
# Accessing an element by index
print(arr[2]) # Output: 3
# Modifying an element
arr[2] = 6
print(arr) # Output: [1, 2, 6, 4, 5]