Download presentation
Presentation is loading. Please wait.
1
Pointers Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng Kung University Last updated: 2 November 2004 Chapter 8
2
Introduction Pointer A variable that holds a memory address Ex 8-1 “Address of” operator & Convention of naming Declaration Indirection (dereference) operator * 提領(取出指標所指物體的內容) The value stored at … Initialization Wild pointer dangerous Pointers addresses variables Manipulating data: Ex 8-2 Examining the address: Ex 8-3
3
Why use pointers Three tasks of using pointers Managing data on the free store Accessing class member data and functions Passing variables by reference to functions Five areas of memory Global name space global variables The free store heap all remaining memory Registers internal housekeeping Code space code The stack local variables, function parameters Concept of free store
4
Using free store Advantages of free store Solves the problem of global and local variable Remains available until you explicitly free it Only functions with access to the pointer tightly controlled interface How to use the free store new delete Ex 8-4 Ex 8-5: applying to object Memory leak
5
Using free store (cont.) Access member data of objects dot operator “.” points-to operator “->” Ex 8-6 Ex 8-7 Stray pointers Ex 8-9 const pointers Ex 8-10
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.