2430 : Introduction to Programming in C

Midterm, and intro to pointers

Today you had your midterm for the class. After that, we had a short lecture on the introduction to pointers.
Basically, remember that pointers are like arrows/cursors, where they point to another variable. An analogy to think about is hyperlinks on web pages. When you click on a link on a web page, it brings you elsewhere -- because the link contains an address -- and whatever it points to is where it will bring you.
Pointers are the same thing. A pointer stores an address in memory. This address is where another variable is located in memory.
Definition of a pointer from your text: a pointer is a data item whose value is the address in memory of some other value.
Why use pointers
These can be found on the first page of the pointers chapter in your textbook, p.454. Each of these will be discussed in the lecture.
  • Pointers allow you to refer to a large data structure.
  • Pointers facilitate sharing data between different parts of a program.
  • Pointers make it possible to reserve new memory during program execution.
  • Pointers can be used to record relationships among data items. (advanced, we will not use)
Your homework is to read chapter 13 on pointers.