To declare an integer array in C++, you can use array notation or the array container.
In this example,
numbers
with predefined values using array notation.#include <iostream>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
std::cout << "Integer Array: ";
for (int i = 0; i < 5; ++i) {
std::cout << numbers[i] << " ";
}
std::cout << std::endl;
return 0;
}
Integer Array: 1 2 3 4 5
In this example,
emptyArray
using the array container.#include <iostream>
#include <array>
int main() {
std::array<int, 0> emptyArray;
std::cout << "Empty Integer Array: ";
for (const auto& element : emptyArray) {
std::cout << element << " ";
}
std::cout << std::endl;
return 0;
}
Empty Integer Array:
In this tutorial, we learned How to Declare an Integer Array in C++ language with well detailed examples.