MC logo

Dynamic Allocation in C

  Practice Questions

  1. In C, malloc can be used for building linked structures, just as the Pascal new operator, and similar to java's new. The C calloc call is usually used for what?

    Give a C declaration, along with any needed executable code, to perform each of the following:

  2. Allocate one node of a linked list. Assume each node is a structure type named node_struct.

  3. Read in an integer, and allocate an array of double of the size you read in.

  4. Add 25 positions to the dynamic array allocated in the last part.

  5. Assuming the variable fred points to a string, create a variable copy which is an exact independent copy of fred, and does not waste any space. That is, it is allocated no larger than needed to hold the string.

  6. How do you relase the memory allocated for any of the above?

<<Pointers and Strings Answer ADT Declarations in C>>