you're specifying the size of array dimension using a value that is not compile time constant .
also the array you are making in the function will be created in the stack part of memory and when you go outside of the function scope the memory allocated by the array will be freed so you cannot return that.
Probably the best way to solve these problems is too create a dynamic array, this way the dimension size can be specified in runtime and you can also return that from the function and the memory will not be freed until you free it manually .
long double** hilbert(int n){
// Making an array of pointers
long double **A = new long double*[n];
for (int i = 0; i < n; i++)
// create an array of size n and put the
// first element address to A[i]
A[i] = new long double[n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
A[i][j]=0.0;
}
}
return A; // Return the array
}
int main() {
// Creating array using the fucntion we've
// just created .
long double** array = hilbert(10);
// Use the array
std::cout << array[0][1] << std::endl;
// free the memory when you're done ...
return 0;
}