Pointers Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.

Slides:



Advertisements
Similar presentations
Data Structures Using C++ 2E
Advertisements

Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Introduction of Memory Allocation. Memory Allocation There are two types of memory allocations possible in c. Compile-time or Static allocation Run-time.
Pointers Typedef Pointer Arithmetic Pointers and Arrays.
Pointers EE2372 Dr. Gerardo Rosiles. Introduction Pointers are one of the most advanced features in the C-language. Allows to generalize code so different.
Informática II Prof. Dr. Gustavo Patiño MJ
Writing a Good Program 6. Pointers and Arrays
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
More Program Flow Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Functions Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
Arrays Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
Expressions and statements Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
Getting Started Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Variables and constants Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
References Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Copyright © 2012 Pearson Education, Inc. Chapter 9: Pointers.
Chapter 9 Pointers Fall 2005 Csc 125 Introduction to C++
Pointers Chapter 9. Getting The Address Of A Variable Each variable in program is stored at a unique address Use address operator & to get address of.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dynamic Memory Allocation 9.8.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Chapter 9 Pointers and Dynamic Arrays (9.1). Pointers A variables which holds the memory address for a variable of a specific type. Call-by-Reference.
Object-Oriented Programming in C++
University of Malta CSA2090: Lecture 4 © Chris Staff 1 of 20 CSA2090: Systems Programming Introduction to C Dr. Christopher Staff.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Introduction Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng Kung University Last updated:
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Programming language – C++ Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng Kung University.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Week 12 Methods for passing actual parameters to formal parameters.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
Standard Version of Starting Out with C++, 4th Edition
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
FIGURE 9-5 Integer Constants and Variables
Pointers Revisited What is variable address, name, value?
Dynamic Memory CSCE 121 J. Michael Moore.
Chapter 9 Pointers Objectives
Dynamically Allocated Memory
Pointers and References
Dynamic Memory Allocation
CSC 253 Lecture 8.
CSC 253 Lecture 8.
understanding memory usage by a c++ program
Dynamic Memory A whole heap of fun….
Pointers & Objects.
Dynamic Memory A whole heap of fun….
Class and Objects In a class, all the functions that operate on the data structure are grouped together in one place along with the data Like a struct.
Destructor CSCE 121.
Dynamic Memory A whole heap of fun….
C Programming Pointers
Dynamic Memory And Objects
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Standard Version of Starting Out with C++, 4th Edition
Pointers, Dynamic Data, and Reference Types
CS148 Introduction to Programming II
Run-time environments
SPL – PS2 C++ Memory Handling.
Introduction to Pointers
Presentation transcript:

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

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

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

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

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