โ Arrays: Definition and Classification
โ 1. Definition of Array
An Array is a linear data structure used to store multiple values of the same data type in continuous (contiguous) memory locations.
โ Each element in an array is accessed using an index (subscript).
๐ Example:
int a[5] = {10, 20, 30, 40, 50};
โ Here:
ais the array name5is the size10, 20, 30, 40, 50are elements- Index starts from
0
๐ Indexing:
- a[0] = 10
- a[1] = 20
- a[2] = 30
- a[3] = 40
- a[4] = 50
โ 2. Characteristics / Features of Array
โ Important points:
- Stores similar type elements (same data type)
- Stored in contiguous memory
- Elements are accessed using index
- Allows random access (direct access)
- Size is usually fixed (static)
โ 3. Classification of Arrays
Arrays are classified mainly into the following types:
โ (A) One-Dimensional Array (1D Array)
A 1D array stores elements in a single row (linear form).
โ Syntax:
datatype array_name[size];
โ Example:
int marks[5];
๐ Representation:
marks[0] marks[1] marks[2] marks[3] marks[4]
โ Uses:
- Storing list of marks
- Roll numbers
- Temperatures of a week, etc.
โ (B) Two-Dimensional Array (2D Array)
A 2D array stores elements in rows and columns (matrix form).
โ Syntax:
datatype array_name[rows][cols];
โ Example:
int matrix[2][3];
๐ Representation:
Row 0 โ a[0][0] a[0][1] a[0][2]
Row 1 โ a[1][0] a[1][1] a[1][2]
โ Uses:
- Matrix calculations
- Tables
- Storing marks of multiple students in subjects
โ (C) Three-Dimensional Array (3D Array)
A 3D array stores elements in multiple layers (3 dimensions).
โ Syntax:
datatype array_name[x][y][z];
โ Example:
int arr[2][3][4];
๐ Uses:
- Advanced matrix operations
- 3D graphics
- Scientific calculations
โ (D) Multi-Dimensional Array
Arrays with more than 2 dimensions are called multi-dimensional arrays.
โ Example:
- 4D array, 5D array etc. (rare in basic programs)
โ 4. Other Classification (Very Useful for Exams)
โ 1. Static Array
A Static Array has a fixed size, decided at compile time.
โ Example:
int a[10];
๐ Advantage:
- Easy access and fast indexing
๐ Disadvantage:
- Size cannot be changed
โ 2. Dynamic Array
A Dynamic Array can grow or shrink during runtime using dynamic memory allocation.
โ Example in C using malloc:
int *a = (int*)malloc(n * sizeof(int));
๐ Advantage:
- Memory is used efficiently
๐ Disadvantage:
- Complex handling
โ 5. Advantages of Arrays
โ Benefits:
- Easy to store and access data
- Fast access using index (random access)
- Simple to use in loops
- Useful for implementing stacks, queues, matrices
โ 6. Disadvantages of Arrays
โ Limitations:
- Fixed size (in static arrays)
- Insertion and deletion are difficult (need shifting)
- Wastage of memory if size is larger
- Stores only same data type elements
โ Conclusion
An array is a linear data structure that stores similar type elements in continuous memory locations. Arrays are mainly classified as 1D, 2D, 3D and multi-dimensional arrays, and also as static and dynamic arrays, based on memory allocation.
.
