1. Definition and Purpose of
Arrays
Definition
An array is a collection
of elements of the
same data type stored
in contiguous memory
locations.
Purpose
Arrays are used to store
multiple values in a single
variable, simplifying data
manipulation and allowing for
efficient operations.
2. Declaring and Initializing Arrays
Syntax
data_type array_name[size];
Examples
int numbers[5]; /* Declaration */
int numbers[5] = {10, 20, 30, 40, 50}; /* Initialization */
3. Declaring and Initializing Arrays
Syntax:
data_type array_name[size];
Examples:
Declaration:
int numbers[5];
Initialization:
int numbers[5] = {10, 20, 30, 40, 50};
Partial Initialization:
int numbers[5] = {10, 20}; // Remaining elements are initialized to 0
4. Accessing and Modifying Array Elements
Accessing
Elements are accessed using an index, starting from 0.
Modifying
Elements can be modified by assigning a new value to the
desired index.
5. Array Operations: Traversal, Searching, and
Sorting
Traversal
Iterating through all elements in an array.
Searching
Finding a specific element in an array.
Sorting
Arranging elements in a specific order.