66.1k views
2 votes
Write a function which (normally) allocates new space for a double array. It should alter its pointer argument to point to the newly allocated space. The size of the array should be a second argument. If this argument is not a valid array size, allocate a single double instead of a whole array. An example call might be:

1 Answer

1 vote

Answer:

see explaination

Step-by-step explanation:

void allocate(double *q,int size)

{

if(size<=0)

q = new double; //Allocates a single double

else

q = new double[size]; //Allocates an array of doubles

}

This function allocates new space for a double array. It alter its pointer argument to point to the newly allocated space.

User RunTarm
by
5.3k points