Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Chapter 6 Data Types
Programming and Data Structure
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Introduction to Programming Lecture 39. Copy Constructor.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Chapter 9. 2 Objectives You should be able to describe: Addresses and Pointers Array Names as Pointers Pointer Arithmetic Passing Addresses Common Programming.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Copyright 2004 Scott/Jones Publishing Starting Out with C++: Early.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Memory Allocation Ming Li Department.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure C Programming Concepts Ming Li.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 9 Pointers and Dynamic Arrays.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Lecture 2 Pointers Pointers with Arrays Dynamic Memory Allocation.
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
Pointers Applications
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Microsoft Visual C++.NET Chapter 61 Memory Management.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Arrays- Part 2 Spring 2013Programming and Data Structure1.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
© 2007 Lawrenceville Press Slide 1 Chapter 10 Arrays  Can store many of the same kind of data together  Allows a collection of related values to be stored.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 Pointers Arrays have a disadvantage: Their size must be known at compile time. We would like the capability to allocate an array-like object of any needed.
1 Chapter 15-2 Pointers, Dynamic Data, and Reference Types Dale/Weems.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Pointer and Array Lists Chapter 3, Summary CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Data Structures Using C++1 Chapter 3 Pointers Dr. Liu.
POINTERS.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Pointers It provides a way of accessing a variable without referring to its name. The mechanism used for this is the address of the variable.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
1 Memory as byte array Pointers Arrays relationship to pointers Operator ‘new’ Operator ‘delete’ Copy ctor Assignment operator ‘this’ const pointer Allocating.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Dynamic Array Allocation char *ptr; // ptr is a pointer variable that // can hold the address of a char ptr = new char[ 5 ]; // dynamically, during run.
PROGRAMMING 1 – HELPER INSTRUCTIONS ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
1 // SPECIFICATION FILE (dynarray.h) // Safe integer array class allows run-time specification // of size, prevents indexes from going out of bounds, //
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
1 CMSC 202 Pointers Dynamic Memory Allocation. 2 A simple variable A variable is drawn as a labeled box int x; X :
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Lecture.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Windows Programming Lecture 03. Pointers and Arrays.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Linked Lists Chapter 6 Section 6.4 – 6.6
Chapter 4 Linked Lists.
Chapter 15 Pointers, Dynamic Data, and Reference Types
Matrices Elements, Adding and Subtracting
Chapter 15 Pointers, Dynamic Data, and Reference Types
Can store many of the same kind of data together
Indirection.
2.2 Introduction to Matrices
Presentation transcript:

Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses in Memory Data Addresses in Memory Declaring Pointer Variables Declaring Pointer Variables Assigning Values to Pointers Assigning Values to Pointers Accessing Data with Pointers Accessing Data with Pointers Arrays and Pointers Arrays and Pointers Operator ‘new’ Operator ‘new’ Operator ‘delete’ Operator ‘delete’ Illustrating the Destructor Illustrating the Destructor Copy Constructor / Overloaded Assignment Operator Copy Constructor / Overloaded Assignment Operator Declaration of dynamicClass Objects Declaration of dynamicClass Objects Chapter 5 – Pointers and Dynamic Memory The Pointer ‘this’ The Pointer ‘this’ dynamicClass Copy Constructor dynamicClass Copy Constructor The C++ Index Operator [] The C++ Index Operator [] Matrices Summary Slides Summary Slides Summary Slides Summary Slides (3 pages)

Main Index Contents 22 Main Index Contents Pointer Illustration

Main Index Contents 33 Main Index Contents Vertical and Horizontal View of Memory

Main Index Contents 44 Main Index Contents Data Addresses in Memory

Main Index Contents 55 Main Index Contents Declare a pointer by stating the type followed by the variable name, but with a "*" added immediately before the name. The pointer ptr is a variable whose value is the address of a data item of the designated type. Declaring Pointer Variables int *intPtr; char *charPtr; type *ptr;

Main Index Contents 6 Assigning Values to Pointers &m is the address of the integer in memory. The assignment statement sets intPtr to point at an actual data item. The Figure illustrates the status of the two variables from the declaration statement and the resulting status after the assignment of a value to intPtr. intPtr = &m; int m = 50, *intPtr;

Main Index Contents 77 Main Index Contents Accessing Data with Pointers int x = 50, y = 100, *px = &x, *py = &y;

Main Index Contents 88 Main Index Contents Arrays and Pointers

Main Index Contents 99 Main Index Contents Operator ‘new’ p = new time24; // *p is 00:00 (midnight) q = new time24(8, 15); // *q is 8:15 AM

Main Index Contents 10 Operator ‘delete’ deallocating a dynamic array, use a slightly different form of delete. Place square brackets [] between delete and the pointer variable name. The system deallocates all of the memory originally assigned to the dynamic array. arr = new T[ARRSIZE]; // allocated space for ARRSIZE objects delete [] arr; // deallocate dynamic array storage

Main Index Contents 11 Main Index Contents Illustrating the Destructor

Main Index Contents 12 Copy Constructor / Overloaded Assignment Operator

Main Index Contents 13 Main Index Contents Declaration of dynamicClass Objects

Main Index Contents 14 The Pointer ‘this’ *thisobjA; this-> memberl

Main Index Contents 15 Main Index Contents dynamicClass Copy Constructor Algorithm

Main Index Contents 16 The C++ Index Operator [] arr[i] = 30;// arr[i] is the address into which 30 is copied t = arr[i] + 4;// add 4 to the value of the element at arr[i]

Main Index Contents 17 Main Index Contents Matrices A Matrix is a two-dimensional array that corresponds to a row-column table of entries of a specified data type. Matrices are referenced using a pair of indices that specify the row and column location in the table. Example: The element mat[0][3] is 2 The element mat[1][2] is 4.

Main Index Contents 18 Main Index Contents Summary Slide 1 §- Pointers contain the address of data in memory… -Data is accessed by applying the dereference operator * §- Operators such as +, ++, and += apply to pointers. §- With such operators, pointers can be used for algorithms involving array traversal, but their primary application is in the allocation and maintenance of dynamic memory.

Main Index Contents 19 Main Index Contents Summary Slide 2 §- vector implementation -The miniVector class illustrates the key points. 1)It allocates dynamic memory using: destructor copy constructor overloaded assignment operator 2)It implements push_back(): Therefore it must control vector capacity in order to minimize dynamic memory reallocation. 3)It allows access to elements by using an index: Therefore the class implements an overloaded index operator

Main Index Contents 20 Main Index Contents Summary Slide 3 §- Two dimensional arrays in C++ -have the same problems as one-dimensional arrays: 1)fixed size 2)no size attribute 3)If it is a function argument, it is necessary to specify the number of columns as a constant.