'How to make an array of pointers and make the user enter the size of it?

I want to make an array, and inside this array there are pointers, like this: int *arrp[size]; and I want the user to enter the size of it. I tried to do this:

#include <iostream>
using namespace std;

int main ()
{
   int size;
   cout << "Enter the size of the array of pointers" << endl;
   cin >> size;
   int *arrp[size];
   
   return 0;
}

but this doesn't work. I also tried to do this:

#include <iostream>
using namespace std;

int main ()
{
   int size;
   cout << "Enter the size of the array of pointers" << endl;
   cin >> size;
   int* arrp[] = new int[size];
   
   return 0;
}

also doesn't work, can someone help?

The error of the first code is that the size must be constant, I tried to fix that by writing the 2nd code but it gives an error for the word "new" in line 9: E0520 initialization with '{...}' expected for aggregate object and another error for the size in the same line: C2440 'initializing': cannot convert from 'int *' to 'int *[]'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source