Question
This assignment introduces you to the concept of the heap, also referred to as the free store. Dynamic memory allocation is used for requesting an
This assignment introduces you to the concept of the heap, also referred to as the free store. Dynamic memory allocation is used for requesting an arbitrarily sized chuck of memory from the system for which you do not know the exact size until the program runs.
Write a program in C that does the following:
1) Using the command "malloc," dynamically allocate a block of memory capable of storing a user-input quantity of floating point variables.
2) Handle malformed user input appropriately.
3) After allocating the memory, use pointers to step through the array and print the values encountered at each slot.
4) What values do you see? The numbers should seem garbled or random. Explain why this is.
5) Use pointers to step through the array again and, at each location, store a random floating point number between 1 and 10. Verify that this was successful by stepping through the array a third time and printing the numbers from the dynamic array to the screen.
6) De-allocate the array when complete.
Please type and display output
Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started