c++ new array code example
Example 1: declare dynamic array c++
int main()
{
int size;
std::cin >> size;
int *array = new int[size];
delete [] array;
return 0;
}
Example 2: how to dynamically allocate an array c++
int* a = NULL;
int n;
cin >> n;
a = new int[n];
for (int i=0; i<n; i++) {
a[i] = 0;
}
. . .
delete [] a;
a = NULL;
Example 3: how to make an array c++
int foo [] = { 16, 2, 77, 40, 12071 };
Example 4: array declaration c++
int foo [5];
Example 5: create array c++
int foo[5] = {0};
Example 6: how to make a array in c++
int a[5] = {1, 2 3, 4, 5};