Intro & Arrays
Dive into this core data structure concept.
Welcome to the world of Data Structures! In computer science, a data structure is a way of organizing and storing data in a computer so that it can be accessed and modified efficiently. The most basic data structure is the **Array**. An array in C is a collection of items of the same type stored at contiguous memory locations. Think of it like a numbered list of boxes, where each box can hold one item. You can access any item in the array directly if you know its index. In C, array indices start at 0.
// An array of integers
int scores[5] = {98, 85, 91, 78, 82};
// Accessing the first element (at index 0)
int firstScore = scores[0]; // firstScore is 98
// Modifying an element
scores[2] = 95; // The third element is now 95Arrays are great for storing ordered collections of data and are very fast for accessing elements by their index. However, their size is fixed at compile time in C. Adding more elements than the array's capacity requires creating a new, larger array and copying the old elements over.