c 2b 2b dynamic allocation full example

Solutions on MaxInterview for c 2b 2b dynamic allocation full example by the best coders in the world

showing results for - "c 2b 2b dynamic allocation full example"
Sol
13 Mar 2020
1// rememb-o-matic
2#include <iostream>
3#include <new>
4using namespace std;
5
6int main ()
7{
8  int i,n;
9  int * p;
10  cout << "How many numbers would you like to type? ";
11  cin >> i;
12  p= new (nothrow) int[i];
13  if (p == nullptr)
14    cout << "Error: memory could not be allocated";
15  else
16  {
17    for (n=0; n<i; n++)
18    {
19      cout << "Enter number: ";
20      cin >> p[n];
21    }
22    cout << "You have entered: ";
23    for (n=0; n<i; n++)
24      cout << p[n] << ", ";
25    delete[] p;
26  }
27  return 0;
28}