L21_more_pointers - 3 Kinds of Program Data 3 Kinds of...

Info iconThis preview shows pages 1–7. 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

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

View Full DocumentRight 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: 3 Kinds of Program Data 3 Kinds of Program Data STATIC DATA : memory allocation exists throughout execution of program static long currentSeed; AUTOMATIC DATA : automatically created at function entry, resides in activation frame of the function , and is destroyed when returning from function YNAMIC DATA explicitly allocated and deallocated during program execution EECS 183 University of Michigan Lecture 21 More Pointers Mary Lou Dorf DYNAMIC DATA : explicitly allocated and deallocated during program execution by C++ instructions written by programmer using operators new and delete Operator Operator new new Syntax Syntax new DataType new DataType [IntExpression] EECS 183 University of Michigan Lecture 21 More Pointers Mary Lou Dorf new allocates memory space from free store (heap) while program is running returns a pointer to (address of ) the memory allocated. delete allows you to deallocate space make it available again, for other uses Allocation of Memory Allocation of Memory STATIC ALLOCATION the allocation DYNAMIC ALLOCATION the allocation of EECS 183 University of Michigan Lecture 21 More Pointers Mary Lou Dorf is the allocation of memory space at compile time . is the allocation of memory space at run time by using operator new . Dynamically Allocated Data Dynamically Allocated Data char* ptr; ptr = new char; *ptr = B; out << *ptr; 2000 ptr EECS 183 University of Michigan Lecture 21 More Pointers Mary Lou Dorf cout << *ptr; NOTE: Dynamic data has no variable name B Dynamically Allocated Data Dynamically Allocated Data char* ptr; ptr = new char; *ptr = B; 2000 ptr ? EECS 183 University of Michigan Lecture 21 More Pointers Mary Lou Dorf cout << *ptr; delete ptr; ptr = 0; NOTE: delete deallocates the memory pointed to by ptr returns memory to the free store which was previously allocated at run-time by operator new Operator Operator delete...
View Full Document

Page1 / 31

L21_more_pointers - 3 Kinds of Program Data 3 Kinds of...

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

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