Question: Write a program in C that does the following: Using the command malloc, dynamically allocate a block of memory capable of storing a user-input quantity

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.

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!