1 Pointers Revisited Linda M c Iver. 2 Pointer Examples int i = 0; 0x2000 0x2001 0x2002 0x2003.

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

 Pointers, Arrays, Destructors Is this random stuff or are these somehow connected?
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Pointer to Structure. Structure variable can be access using pointers int a=10,*p; Here p  is an integer type pointer variable, p can hold the address.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
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.
Class 3: Linked Lists. cis 335 Fall 2001 Barry Cohen What is a linked list? n A linked list is an ordered series of ‘nodes’ n Each node contains some.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure C Programming Concepts Ming Li.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Pointers.
Pointers Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
Overview Pointer Variables Pass by Value Pass by Reference (or by Pointer) Arrays.
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.
Some Example C Programs. These programs show how to use the exec function.
Pointers CSE 2451 Rong Shi.
Copyright © 2012 Pearson Education, Inc. Chapter 9: Pointers.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
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.
Chapter 7: Pointers Basic concept of pointers Pointer declaration Pointer operator (& and *) Parameter passing by reference.
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.
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.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
Pointer Arithmetic CSE 2541 Rong Shi. Pointer definition A variable whose value refers directly to (or "points to") another value stored elsewhere in.
Lecture 6 C++ Programming Arne Kutzner Hanyang University / Seoul Korea.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
Review 1 List Data Structure List operations List Implementation Array Linked List.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Arrays, Part 2 We have already learned how to work with arrays using subscript notation. Example: float myData[] = {3.5, 4.0, 9.34}; myData[0] += 2; printf("myData[0]
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
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.
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 Memory as byte array Pointers Arrays relationship to pointers Operator ‘new’ Operator ‘delete’ Copy ctor Assignment operator ‘this’ const pointer Allocating.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
1. Generic Pointer 2. NULL Pointer 3. Wild Pointer 4. Dangling Pointer.
CCSA 221 Programming in C CHAPTER 11 POINTERS ALHANOUF ALAMR 1.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Pointers Data Structures CSI 312 CSI Dept. Dr. Yousef Qawqzeh.
Pointers What is the data type of pointer variables?
Learning Objectives Pointers Pointer in function call
Memory and Addresses Memory is just a sequence of byte-sized storage devices. The bytes are assigned numeric addresses, starting with zero, just like the.
Pointer.
Basic notes on pointers in C
Pointer Basics Psst… over there.
Local Variables, Global Variables and Variable Scope
Pointers Lecture 1 Thu, Jan 15, 2004.
C++ Pointers and Strings
C Programming Lecture-8 Pointers and Memory Management
POINTER CONCEPT 4/15/2019.
C Programming Pointers
A simple function.
The Stack.
Pointer Basics Psst… over there.
Pointer Arithmetic By Anand George.
C++ Pointers and Strings
Pointers.
CS148 Introduction to Programming II
POINTER CONCEPT 8/3/2019.
Introduction to Pointers
Presentation transcript:

1 Pointers Revisited Linda M c Iver

2 Pointer Examples int i = 0; 0x2000 0x2001 0x2002 0x2003

3 Pointer Examples 0 int i = 0; i 0x2000 0x2001 0x2002 0x2003

4 Pointer Examples 0 int i = 0; int* intPtr = NULL; i 0x2000 0x2001 0x2002 0x2003 int i = 0;

5 Pointer Examples 0NULL int i = 0; int* intPtr = NULL; i intPtr 0x2000 0x2001 0x2002 0x2003 int i = 0;

6 Pointer Examples 0 NULL int i = 0; int* intPtr = NULL; intPtr = &i; i intPtr 0x2000 0x2001 0x2002 0x2003

7 Pointer Examples 0 0x2000 int i = 0; int* intPtr = NULL; intPtr = &i; i intPtr 0x2000 0x2001 0x2002 0x2003

8 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i intPtr *intPtr i &intPtr

9 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr *intPtr i &intPtr

10 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr i &intPtr

11 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i &intPtr

12 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i0 &intPtr

13 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i0 &intPtr0x2001

14 Pointer Examples &i == intPtr == 0x2000 i == *intPtr == 0 int i = 0; int* intPtr = NULL; intPtr = &i; 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003

15 Pointer Examples 'b' char c = 'b'; c 0x2000 0x2001 0x2002 0x2003

16 Pointer Examples 'b'NULL char c = 'b'; char* charPtr = NULL; c charPtr 0x2000 0x2001 0x2002 0x2003

17 Pointer Examples 'b'NULL char c = 'b'; char* charPtr = NULL; c charPtr 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?

18 Pointer Examples 'b'NULL 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; c charPtr initial 0x2000 0x2001 0x2002 0x2003

19 Pointer Examples 'b'0x2000 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; c charPtr initial 0x2000 0x2001 0x2002 0x2003

20 Pointer Examples 'b'0x2000 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; c charPtr initial 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?

21 Pointer Examples 'b'0x2002 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; charPtr = &initial; c charPtr initial 0x2000 0x2001 0x2002 0x2003

22 Pointer Examples 'b'0x2002 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; charPtr = &initial; c charPtr initial 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?

23 Pointer Summary A pointer holds an address & gives you the address of a variable *somePtr is a de-reference, which gives you the value of the variable pointed to by somePtr Like variables, pointers have a particular type