syntax of using new function for creating array in c++ code example

Example 1: how to make an array c++

int foo [] = { 16, 2, 77, 40, 12071 };

Example 2: how to create an array with a variable in it c++

// arrays as parameters
#include <iostream>
using namespace std;

void printarray (int arg[], int length) {
  for (int n=0; n<length; ++n)
    cout << arg[n] << ' ';
  cout << '\n';
}

int main ()
{
  int firstarray[] = {5, 10, 15};
  int secondarray[] = {2, 4, 6, 8, 10};
  printarray (firstarray,3);
  printarray (secondarray,5);
}

Tags:

Cpp Example