An array is a fixed-size collection that stores multiple values of the same data type in one place. It's handy for storing data with a known, fixed count — like 5 student marks, 10 product prices, or 7 weekday names.
cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string courses[3] = {"HTML", "CSS", "C++"};
cout << courses[0] << endl;
courses[2] = "JavaScript";
for (int i = 0; i < 3; i++) {
cout << courses[i] << endl;
}
return 0;
}courses[3] is an array that can hold 3 items. Since indexing starts at 0, courses[0] is the first item, and courses[2] is the third. The loop here prints out every item in the array.
You should see
HTML HTML CSS JavaScriptInfo
An array's size is fixed. If you don't need the size to change and you already know how many items you'll have, an array is a good fit. If the item count needs to grow or shrink, reach for a vector instead.