Docsity

Dynamic Memory Allocation - Introduction to Programming - Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download Dynamic Memory Allocation - Introduction to Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Introduction to Programming

Lecture 24

Today’s Agenda

 Memory Allocation

  • Dynamic memory allocation
  • Advantages/disadvantages of

Dynamic and static memory

allocation

  • Common programming errors while

using Dynamic memory allocation

Compile Time Allocation

Dynamic Memory Allocation

Pointers

void

Pointer

void *ptr ;

Cast

( int * ) ptr ;

NULL

calloc ( 1000 , sizeof ( int ) ) ;

( int * ) calloc ( 1000 , sizeof ( int ) ) ;

Example 1 int *iPtr ; iPtr = ( int * ) calloc ( 1000 , sizeof ( int ) ) ; if ( iPtr == NULL ) exit ( ) ;

void * malloc ( n ) ;

Number of
bytes required