lecture-11 - 50 Object Oriented Programming C Classes R.B...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: 50 Object Oriented Programming C++ Classes R.B. Lenin Winter 2006 DA-IICT Dynamic Memory Allocation with Operators new and delete – new and delete – Better dynamic memory allocation than C’s malloc and free – new - automatically creates object of proper size, calls constructor, returns pointer of the correct type – delete- destroys object and frees space – Example: – TypeName *typeNamePtr; – Creates pointer to a TypeName object – typeNamePtr = new TypeName; – new creates TypeName object, returns pointer (which typeNamePtr is set equal to) – delete typeNamePtr; – Calls destructor for TypeName object and frees memory 51 Object Oriented Programming C++ Classes R.B. Lenin Winter 2006 DA-IICT Dynamic Memory Allocation with Operators new and delete (II) • Initializing objects double *thingPtr = new double( 3.14159 ); – Initializes object of type double to 3.14159 int *arrayPtr = new int[ 10 ]; – Create ten element int array, assign to arrayPtr ....
View Full Document

This note was uploaded on 09/15/2010 for the course CSE IT325 taught by Professor Maniklaldas during the Spring '09 term at Punjab Engineering College.

Page1 / 10

lecture-11 - 50 Object Oriented Programming C Classes R.B...

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

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