Lecture10-2 - DataStructures CSCI 132 Spring 2012 Lecture...

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 10 Dynamic Memory and Pointers
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Multiple includes for .h files Sometimes more than 1 source file needs to include a given .h file. The compiler may give an error, since the .h file is defined twice. Use a pre-processor directive to avoid this problem: #ifndef STACK_H #def STACK_H typedef . ... class Stack { ... };
Background image of page 2
3 Recall Arrays int numbers[5]; The name of the array , numbers, contains the base address of the array. numbers, is a pointer.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Declaring a Pointer A pointer is a variable that can store the memory address of some piece of data. Declaring a pointer: float *p; p is a pointer that can store a memory address of a floating point variable.
Background image of page 4
Allocating Memory Declaring a pointer does not automatically give it a valid memory address: float *p; To allocate memory, use the key word: new p = new float; This is dynamic allocation of memory. p
Background image of page 5

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

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

This document was uploaded on 03/09/2012.

Page1 / 18

Lecture10-2 - DataStructures CSCI 132 Spring 2012 Lecture...

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

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