If I want to dynamically allocate memory for array of pointers of int, how can I achieve this requirement?
Suppose I declare an array of pointers of int like this:
int (* mat);
mat = new int * [K];
cannot convert 'int**' to 'int (*)' in assignment
int (*mat) = NULL;
int (* array_pointers);
mat = array_pointers;
cannot convert 'int (*)' to 'int (*)' in assignment
int (* mat); is a pointer to array of
int with unspecified size (not an array of pointers). In C++ it is an error, the dimension cannot be omitted in C++.
Your question says
new int *[K] so I assume this is really a C++ question. The expression
new T[n] evaluates to a
T * already, there is no implicit conversion.
The code to allocate an array of null pointers using
int **mat = new int *();
mat points to the first one of those. Another option (less commonly used) is:
int * (*mat) = new int *();
*mat designates the entire array of 10 pointers.
NB. This sort of code is not useful for anything except demonstration purposes perhaps, whatever you are trying to do has a better solution.