Question: Programming task 5.3: Dynamic Array (30 pts) // t his is a c++ course In this task, we practice dynamic memory allocation and extending arrays

Programming task 5.3: Dynamic Array (30 pts) // this is a c++ course

In this task, we practice dynamic memory allocation and extending arrays

Two functions need to be implemented in this task. To collect points, some kind of implementation must exist for both functions. Remember, valgrind errors must not be present to get full points.

  1. Implement function int *create_dyn_array(unsigned int n) that allocates an int array for n integers. n is given as argument to the function when it is called. After allocating the array, the function should read the given number of integers to the array from user, using the scanf function. After the right amount of integers have been read, the function returns pointer to the dynamically allocated array.

  2. Implement function int *add_dyn_array(int *arr, unsigned int num, int newval) that adds a single integer to the existing dynamically allocated array of integers (arr). The length of the existing array is num, and the new integer to be added is given in parameter newval. Youll need to ensure that array is extended to hold the additional integer. Check that the function works correctly when called several consecutive times.

Programming task 5.3: Dynamic Array (30 pts) // this is a c++

5.3: Dynamic Array > src > C main.c > maino 1 #include 2 #include 3 #include "source.h" 4 5 void printarray(const int *array, int size) { 6 printf("{ "); 7 for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!