Alternate Version of STARTING OUT WITH C++ 4th Edition

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Call By Address Parameters (Pointers) Chapter 5. Functions that “return” more than a single value What if we need more than one value to be returned from.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
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.
Copyright © 2012 Pearson Education, Inc. Chapter 9: Pointers.
1 Pointers & functions Pointers allow us to simulate pass by reference. void swap(int &a, int &b) { int temp = a; a = b; b = temp; } int main () { int.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 10: Pointers by.
1 CSE1301 Computer Programming Lecture 16 Pointers.
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 C Programming CE
Pointers: Part I. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 10: Pointers.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 9: Pointers.
1 Chapter 9 Pointers. 2 Topics 8.1 Getting the Address of a Variable 8.2 Pointer Variables 8.3 Relationship Between Arrays and Pointers 8.4 Pointer Arithmetic.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
1 CSE1301 Computer Programming Lecture 16 Pointers.
Copyright © 2012 Pearson Education, Inc. Chapter 9: Pointers.
Lesson 9 Pointers CS 1 Lesson 9 -- John Cole1. Pointers in Wonderland The name of the song is called ‘Haddock’s Eyes’.” “Oh, that’s the name of the song,
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified by use by the MSU CMPS Dept. Chapter 10:
C++ Pointers Copies from SEE C++ programming course and from Starting Out with C++: Early Objects, 8/E by Tony Gaddis, Judy Walters and Godfrey Muganda.
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.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9: Pointers.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 6 (Pointers) © CPCS
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
Data Structures Using C++1 Chapter 3 Pointers Dr. Liu.
Review 1 List Data Structure List operations List Implementation Array Linked List.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 8 Arrays.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter 6.
Pointer. lvalues In C++, any expression that refers to an internal memory location is called an lvalue Appear on left side of assignment statement e.g.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1  Lecture 12 – Pointer FTMK, UTeM – Sem /2014.
Copyright © 2012 Pearson Education, Inc. Chapter 9: Pointers.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9-1 Pointer Variables Pointer variable : Often just called a pointer, it's.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Pointers Lecture: 5. Topics 1 Pointers and the Address Operator 2 Pointer Variables 3 The Relationship Between Arrays and Pointers 4 Pointer Arithmetic.
Topic 5 Addresses, Pointers and Arrays. 2 Objectives (Textbook Chapter 14) You should be able to describe: Addresses and Pointers Pointer Operators Pointer.
Standard Version of Starting Out with C++, 4th Edition
Chapter 9: Pointers.
Lecture 9 Files, Pointers
Chapter 10: Pointers Starting Out with C++ Early Objects
Pointers and Pointer-Based Strings
Pointer.
Chapter 10: Pointers Starting Out with C++ Early Objects Ninth Edition
Lecture 6 C++ Programming
Chapter 10: Pointers Starting Out with C++ Early Objects
Dynamic Memory Allocation
Chapter 9: Pointers.
Chapter 10: Pointers Starting Out with C++ Early Objects Ninth Edition
Chapter 9: Pointers.
Alternate Version of STARTING OUT WITH C++ 4th Edition
Constant pointers and pointers to constants
Pointers & Functions.
Alternate Version of STARTING OUT WITH C++ 4th Edition
Alternate Version of STARTING OUT WITH C++ 4th Edition
Chapter 10: Pointers Starting Out with C++ Early Objects Ninth Edition
Pointers and Pointer-Based Strings
Pointers & Functions.
Standard Version of Starting Out with C++, 4th Edition
pointer-to-pointer (double pointer)
Pointers.
Presentation transcript:

Alternate Version of STARTING OUT WITH C++ 4th Edition Chapter 10 Pointers Copyright 2004 Scott/Jones Publishing

Topics (continued) 10.7 Pointers as Function Parameters 10.9 Returning Pointers from Functions Chapter 10 slide 2

10.7 Pointers as Function Parameters A pointer can be a parameter Works like a reference parameter to allow change to argument from within function A pointer parameter must be explicitly dereferenced to access the contents at that address Chapter 10 slide 3

Pointers as Function Parameters Requires: 1) asterisk * on parameter in prototype and heading void getNum(int *ptr); 2) asterisk * in body to dereference the pointer cin >> *ptr; 3) address as argument to the function getNum(&num); Chapter 10 slide 4

Pointers as Function Parameters void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp; } int num1 = 2, num2 = -3; swap(&num1, &num2); See pr10-11.cpp and pr10-12.cpp Chapter 10 slide 5

10.9 Returning Pointers from Functions Pointer can be return type of function int* newNum(); Function must not return a pointer to a local variable in the function Function should only return a pointer to data that was passed to the function as an argument to dynamically allocated memory Chapter 10 slide 6