Write a function named allocAndInit() that will receive the following parameters: An int containing the number of doubles to create dynamically, and a double that contains the initial value that every item in the new memory will be initialized to. The function returns a pointer to the newly created data. It may not be a void pointer.
double * allocAndInit(int n, double value)
{
double *value = (double*)malloc(n*sizeof(double);
return value;
}
Help writing in C language. i have this so far but i am lost. please help?
having value in the parameters and value as a local variable is confusing. Change that to doubleList, or something.
Then initialize a value to that first pointer.
double *d = doubleList;
then loop through double, setting
*d = value;
and then d++ will move to the next double. Make sure to only loop through n doubles.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment