1. Engineering
  2. Computer Science
  3. im trying to create a function that mallocs an instance...

Question: im trying to create a function that mallocs an instance...

Question details

i'm trying to create a function that mallocs an instance and it's pointer (d). This is what I have, but I wanted to see if it was correct? it's supposed to be the basis of an array of integers.

struct intRA
{
int length;
int *d;
};

struct intRA* m_intRA(int length)
{
   struct intRA *ra = malloc(sizeof(struct intRA));

   ra->length = length;

   ra->d = (int *)malloc(length * sizeof(int));

   return ra;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution