Array C++ example
Example 1: print an array c++
#include <iostream>
using namespace std;
int main() {
int numbers[5] = {7, 5, 6, 12, 35};
cout << "The numbers are: ";
for (const int &n : numbers) {
cout << n << " ";
}
cout << "\nThe numbers are: ";
for (int i = 0; i < 5; ++i) {
cout << numbers[i] << " ";
}
return 0;
}
Example 2: how to make an array c++
int foo [] = { 16, 2, 77, 40, 12071 };
Example 3: array declaration c++
int foo [5];
Example 4: take input from user in array c++
int x[] = {19, 10, 8, 17, 9, 15};
Example 5: arrays in c++
int baz [5] = { };
Example 6: array syntax in c++
int foo[] = { 10, 20, 30 };
int foo[] { 10, 20, 30 };