Memory Allocation in C++: Pointers and Dynamic Allocation, Slides of Computer Programming

An introduction to memory allocation in c++ through pointers and dynamic allocation functions such as malloc, calloc, realloc, new, and delete. Topics covered include memory allocation for classes and objects, pointer to a class, and the process of allocating, populating, and deleting memory. Examples are given to illustrate the usage of these functions.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

somo
somo 🇮🇳

4.8

(4)

70 documents

1 / 33

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction of Programming
Lecture 28
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21

Partial preview of the text

Download Memory Allocation in C++: Pointers and Dynamic Allocation and more Slides Computer Programming in PDF only on Docsity!

Introduction of Programming

Lecture 28

Today’s Lecture  How memory allocation is done in C++  How is it different from C style  Advantages of memory allocation in C++  Uses of memory allocation

  • Classes
  • Objects

Pointers to a class

malloc ( ) ; calloc ( ) ; realloc ( ) ;

malloc ( 10 * ( sizeof ( int ) ) ) ;

new

new int ;

new char ; new double ; Example

delete

int * iptr ; iptr = new int [ 10 ] ; Example

new data_type [ Number_of_locations ] ;

new double [ 10 ] ;

Example

Date *dptr ;

dptr is a pointer to an object of type date

Example

dptr = new Date ;