Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C Programming, Functions: void* allocateArray(int elemSize, int elemNum) - implement a generic function that allocates memory for different types of array. It is applicable

In C Programming,

Functions:

void* allocateArray(int elemSize, int elemNum) - implement a generic function that allocates memory for different types of array. It is applicable to arrays with types of int, string, double, float and even struct. This function takes desired element size and the number of elements as inputs, and returns a void*. The number of array elements is hidden at location [-2], the element size is hidden at location [-1]. void freeArray(void* array) - implement a function that frees the memory which you use allocateArray function to allocate. The struct to use is: typedef struct employee{ char name[10]; int age; }employee; Main Program: 1. Use allocateArray function to allocate a 3 elements array of struct employee. 2. Initialize the elements as follows: employee 0: age 20, name "Mark"; employee 1: age 26, name "Cassie"; employee 2: age 40, name "Paul"; 3. Extract the element size and the number of elements from the string array and print them onto the console. 4. Print out the contents of the array onto the console. 5. Free the string array memory using freeArray function. Example output: The number of elements is:3 The element size is:8 Employee 0, name is Mark, age is 20 Employee 1, name is Cassie, age is 26 Employee 2, name is Paul, age is 40

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions