double *f(int n, double v)
{
double *a, *p;
a = malloc(n * sizeof(double));
if (a != NULL)
for (p = a; p < a + n; p++)
*p = v;
return a;
}
Can you explain me what this function is needed for? Does it copy the content of v in n? If yes, why does it return a? I really don’t get it… Thanks in advance.
So if I called this function:
Now I have:
So to answers your questions:
vis a double andnis an int, that doesn’t even make sense. It makes an arraynlarge and initializes it with the valuev.aso you have a reference to the newly created array. (see example above on how it could be used)