 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

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.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
1 Pointers Lecture Introduction Pointers  Powerful, but difficult to master  Simulate pass-by-reference  Close relationship with arrays and.
CS 141 Computer Programming 1 1 Pointers. Pointer Variable Declarations and Initialization Pointer variables –Contain memory addresses as values –Normally,
Pointers 1 Pointers Pointers  In chapter three we looked at passing parameters to functions using call by value, and using call by reference, using reference.
Pointers Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
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.
What are Pointers? Different from other normal variables which can store values. pointers are special variables that can hold the address of a variable.
 Review structures  Program to demonstrate a structure containing a pointer.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location. This is.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
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.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
 2003 Prentice Hall, Inc. All rights reserved Introduction Pointers –Powerful, but difficult to master –Simulate pass-by-reference –Close relationship.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Review 1 List Data Structure List operations List Implementation Array Linked List.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Pointers Class #9 – Pointers Pointers Pointers are among C++ ’ s most powerful, yet most difficult concepts to master. We ’ ve seen how we can use references.
C++ Programming Lecture 17 Pointers – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
System Programming Practical Session 7 C++ Memory Handling.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
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.
Revision on C++ Pointers TCP1201: 2013/2014. Pointer Basics  Why pointer is important? 1. Reference/Point to existing data without cloning the data.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
1. Pointers –Powerful, but difficult to master –Simulate pass-by-reference –Close relationship with arrays and strings 2.
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
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?
Variables Mr. Crone.
Standard Version of Starting Out with C++, 4th Edition
Pointers & Arrays.
Command Line Arguments
Learning Objectives Pointers Pointer in function call
Visit for more Learning Resources
Pointer.
Programming fundamentals 2 Chapter 2:Pointer
void Pointers Lesson xx
Andy Wang Object Oriented Programming in C++ COP 3330
Pointer Data Type and Pointer Variables
Pointer Basics Psst… over there.
Buy book Online -
Value returning Functions
CS 2308 Exam I Review.
Pointers Kingdom of Saudi Arabia
Functions Pass By Value Pass by Reference
Introduction to C++ Programming Language
Dynamic Memory A whole heap of fun….
5.1 Introduction Pointers Powerful, but difficult to master
Pointers Lecture 1 Thu, Jan 15, 2004.
CSCE 206 Lab Structured Programming in C
C Programming Lecture-8 Pointers and Memory Management
Arrays Arrays A few types Structures of related data items
POINTER CONCEPT 4/15/2019.
Pointers & Arrays.
Pointers and dynamic objects
The Stack.
Pointer Data Type and Pointer Variables
Pointer Basics Psst… over there.
Pointer Data Type and Pointer Variables
Pointers.
CS148 Introduction to Programming II
POINTER CONCEPT 8/3/2019.
Presentation transcript:

 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers

int a = 10; float x = 17.24; char c = ‘q’; ‘q’ a x c (1ab) (2fe) (3cd)

int a = 10; float x = 17.24; char c = ‘q’; ‘q’ 5fb a x c (1ab) (2fe) (3cd)

int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ‘q’ a x c (1ab) (2fe) (3cd) ptr

int a = 10; float x = 17.24; char c = ‘q’; cout << a; cout << &a; ‘q’ a x c (1ab) (2fe) (3cd)

int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; ‘q’ 1ab a x c (1ab) (2fe) (3cd) ptr

int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; ‘q’ 1ab a x c (1ab) (2fe) (3cd) ptr

int a = 10; float x = 17.24; char c = ‘q’; int *ptr; ptr = &a; ‘q’ a x c (1ab) (2fe) (3cd) 1ab ptr

#include using std::cout; using std::endl; int main() { int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<* intptr << intptr <<& intptr << endl; return 0; }

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<* intptr << intptr <<& intptr << endl; 10 y cc (1ab) (4fe)

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<*intptr << ptr <<&intptr << endl; ; 10 y cc (1ab) (4fe) intptr

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<*intptr <<intptr <<&intptr << endl; 10 y cc (1ab) (4fe) 4fe intptr

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<* intptr << intptr <<& intptr << endl; 10 y cc (1ab) (4fe) 4fe intptr

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; *intptr = 32; cout << y <<*intptr << intptr <<& intptr << endl; y cc (1ab) (4fe) 4fe intptr

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; cout << y <<*intptr <<intptr<<&intptr << endl; y cc (1ab) (4fe) 4fe intptr (55a)

int y, cc = 10; int* intptr; intptr = &cc; y = *intptr; cout << y <<*intptr <<intptr <<&intptr << endl; y cc (1ab) (4fe) 4fe intptr (55a) Output fe 55a

Memory setup Pointer declaration Address operator Indirection Printing addresses or pointers