Answers/Solutions to Exercises in Chapter 4, Exercise 7

E7: In the following program we allocate a memory segment of 20 bytes. What will happen to the memory segment after the program terminates?
    #include <stdlib.h>

    int main()
    {
        char *p;

        p = malloc(20);
        strcpy(p,"hello");
        return 0;
    }

A7: All dynamic memory allocated to a running program is "returned" to the operating system after the execution terminates.

Back to Answers/Solutions Index                          Back to Answers/Solutions for Chapter 4 Index