CSC209H5 Chapter Notes - Chapter 4: C String Handling, C Dynamic Memory Allocation, Memory Leak

14 views2 pages

Document Summary

Csc209h5s - software programming and tools (winter 2018) The type of the value returned from the function malloc is void *. The parameter to malloc is the size of the chunk of memory to allocate and the return value is a pointer to that newly-allocated memory. Consider the code fragment int *a = malloc(sizeof(int) * 20); Assume (for the purposes of answering this question) that integers are 4 bytes and pointers are 8 bytes. When calling free to reset the values, the freed memory will be left unchanged. Dereferencing a pointer that has already been freed. Leaving unfreed but no longer accessible memory on the heap (true) Regularly allocating a little more memory than you actually need. Consider this code int **heights = malloc( sizeof ( int *) * 2 ); height[ 0 ] = malloc( sizeof ( int ) * num_boys); height[ 1 ] = malloc( sizeof ( int ) * num_girls);

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents