Question: Dynamic Arrays in C Just like we can allocate run-time memory in C++ by using new and delete, we can allocate run-time memory in C

 Dynamic Arrays in C Just like we can allocate run-time memory
in C++ by using new and delete, we can allocate run-time memory

Dynamic Arrays in C Just like we can allocate run-time memory in C++ by using new and delete, we can allocate run-time memory in C Programming as well. For this, we use malloc() and/or calloc() functions to allocate memory. For example, 1. int *ptr (int ) malloc (10 sizeof (int)) This allocates space for a dynamic array of 10 integers. To deallocate this memory, we need to use the free () function. For example, free (ptr) Unlike with new and delete, if the allocated dynamic memory is not deemed sufficient, we can increase the allocated run-time memory. This is done via realloc ) function For example, ptr realloc (ptr, 20 sizeof (int)) This statement now increases the allocated memory size to an array of 20 integers. Now, write a C programthatcalulates the running average of doubles. . Compute the cumulative sum and the running average of the numbers Display the list of all the numbers that have been entered by the user and The loop needs to terminate if the user decides there are no more numbers The user does not know how many numbers are there in total, so your Prompt the user for the value of double in a loop. entered by the user. their average after every new entry. to enter. allocated memory must grow as the user decides to enter more numbers. Initially, allocate run-time memory for one double only and obtain the value of the double from the user. In the loop, use the realloc() function to increase the memory allocated. Keep growing your memory and reading new double values as long as the user wants to enter new numbers. For every entry, you need to update the sum and the average of the values entered by the user, and display the list of numbers as well as the updated average. After writing the code, save it as LabEC A.a. Compile and test it using the gcc compiler, not the g++ compiler and upload on Canvas

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!