In C++, the code would look as follows:
#include <vector>
void function()
{
std::vector<double> array(100);
//some work that can return when or throw an exception
//...
return;
}
If you really don't want to initialize the array elements and don't need to resize the array and don't need iterators, you can also use:
#include <memory>
void function()
{
std::unique_ptr<double[]> array(new double[100]);
//some work that can return when or throw an exception
//...
return;
}
In both cases you access the array elements with array[0]
, array[1]
, etc.
Finally, if you don't need to transfer ownership of the data out of the function, know the size of the array at compile time, and the size isn't too large, you may also consider having a direct array object:
void function()
{
double array[100]; // uninitialized, add " = {}" to zero-initialize
// or:
std::array<double, 100> array; // ditto
//some work that can return when or throw an exception
//...
return;
}