CIS 22B - Notes for Thursday, 10/8

Announcements and Reminders

Recording

Pointers

What is a pointer?

Why are pointers used?
  • As function arguments
  • To iterate through an array
How to ...
  • Declare a pointer
  • Assign a pointer
  • Dereference a pointer
  • The dereferencing operator or indirection operator
  • Use a pointer as a function argument
    • Compare types of arguments
      • Pass by value
      • Pass by reference
      • Pass by address
Pointer Arithmetic
  • With one-dimensional arrays
Example
  • With two-dimensional arrays
Example


Other stuff 

Return by address 

pointer to const, const pointer

Is this OK?

int a[5] = { 98, 76, 84, 100, 95 };

int b[5];

b = a;

A pointer to pointer


Videos

Buckys C++ Programming Tutorials - 38 - Introduction to Pointers (6 minutes) This is a good introduction to pointers

Buckys C++ Programming Tutorials - 39 - Pass by Reference with Pointers (9 minutes)

Buckys C++ Programming Tutorials - 41 - Pointers and Math (6 minutes)