2_Answers_MemAlloc_10

2_Answers_MemAlloc_10 - CIS 15BG 1 Questions Chapter 10:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Questions Chapter 10: POINTER APPLICATIONS Memory Management 1. Write fragments of code to allocate memory as specified below. Validation: if not enough memory, print a message using MEM_ERROR and exit. #define MEM_ERROR printf("Not enough memory!\n") (A) . Allocate a double using malloc. Validation required. double *ptr; ptr = (double *) malloc( sizeof(double) ); if(ptr == NULL) MEM_ERROR, exit(100); (B). Allocate a double using calloc . Validation required. double *ptr; ptr = (double *) calloc( 1 , sizeof(double) ); if( !ptr ) MEM_ERROR, exit(100); (C). Allocate a list of n integers using malloc . Validation required. int *list; list = (int *) malloc( n * sizeof(int)); if( !list ) MEM_ERROR, exit(100); (D). Allocate a list of n integers using calloc . Validation required. int *list; list = (int *) calloc( n, sizeof(int) ); if( !list ) MEM_ERROR, exit(100); (E). Change the size of a dynamically allocated list from the existing size to m integers. Assume m > 0. Validation required.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Winter '10 term at DeAnza College.

Page1 / 5

2_Answers_MemAlloc_10 - CIS 15BG 1 Questions Chapter 10:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online