@mmderbi
π C++ Programming β Part 7: Arrays
So far, weβve stored one value per variable.
But what if you need to store many values of the same type? π€
Thatβs where arrays come in!
πΉ What Is an Array?
An array is a collection of elements stored under one name β like a list π¦
Example π
int numbers[5] = {10, 20, 30, 40, 50};
β
This creates 5 integer slots:
numbers[0] = 10, numbers[1] = 20, β¦ numbers[4] = 50
---
πΉ Accessing Elements:
cout << numbers[2]; // Output: 30
πΉ Using Loops with Arrays:
for (int i = 0; i < 5; i++) {
cout << numbers[i] << " ";
}
β
Prints: 10 20 30 40 50
---
πΉ Why Use Arrays?
They make it easy to manage large sets of data without creating dozens of variables πͺ
πΉ Coming next (Part 8):
Weβll explore functions β how to organize your code and make it reusable π§