Held: Wednesday, 19 February 2003
Today we begin our consideration of pointers, one of the key type
constructors that set C apart from other languages.
- I will not be in class on Friday. Mr. Gum will teach in my stead.
I will prepare a lab, but he may not use it. In case you care, I'll
be going to the steering committee meeting of the EdMedia World Conference
on Educational Multimedia, Hypermedia, and Telecommunications.
- Does anyone want to record information on Friday's class
for preserving in the Eboard?
- I'm still working on preparing your exam (and on getting to grading
- Any thoughts about the format of class, EBoards, and/or Web site?
- Pointers in C.
- Basic Operations.
- Memory allocation.
- If almost every data value you write in a program gets stored in
memory, each data value has an effect address.
- We typically refer to the data type that contains addresses as
- Most languages use pointers in some way.
- In Scheme, Cons cells are pairs of pointers.
- In Java, each object variable is really a pointer to an object
(or perhaps a pointer to a pointer; I'll admit that I haven't
looked at the definition in depth).
- Pointers provide great power.
- With great power comes great responsibility.
- With great power comes great capability for screwing up.
- Some languages make pointers implicit, and give programmers as little
access as possible.
- Some languages make pointers explicit and give programmers access to
- Guess what C does?
- C makes pointers a key data type, and emphasizes them in many different
aspects of the language.
- In some ways, the use of pointers simplifies the language. For example,
C is always pass by value.
- But you have to understand the implication of pass by value with
- In C, you typically declare pointers with
- This means that
pointer-variable is intended to store the
address of a memory location that contains a value of type type.
- Pointer arithmetic:
- Meaning: The address after the thing pointer-var points to.
- Lots of variants:
point to the next thing
pointer-var + offset: ...
- You can also use pointers as a mechanism for dynamically creating and
- The standard C library C provides a few nice mechanisms for allocating
and deallocating memory:
(and some variants).
- Detour: Stack memory and heap memory.
- Do you need
free? No. They can
- More to come ...
Tuesday, 7 January 2003 [Samuel A. Rebelsky]
- Created generic version to set up course.