auto print array code 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: c++ print every element in array
#include<iostream>
int main()
{
int array[8] = {1,2,3,4,5,6,7,8};
int i = 0;
while (i <= sizeof(array)/sizeof(int))
{
std::cout << array[i];
i++;
}
}