Array
Programming
This program demonstrates C-style arrays, which are fixed-size collections of elements of the same type.
Implementation
#include <iostream>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; ++i) {
std::cout << "Element " << i << ": " << numbers[i] << std::endl;
}
return 0;
} Key Concepts
- Array Declaration:
int numbers[5]declares an array of 5 integers - Array Initialization:
5initializes the array elements - Array Indexing:
numbers[i]accesses the element at indexi(0-based) - Arrays have fixed size and cannot be resized
Output
Element 0: 1
Element 1: 2
Element 2: 3
Element 3: 4
Element 4: 5