Sections 0101, 0102, 0103 and Honors, Fall 1995
Tuesday November 21, 1995
Assigned Reading: 13.1 - 13.2
Handouts (available on-line):
- We looked at a strange error that occurs when you use
the variable name strlen as the name of a global variable
in the following program and sample run.
This problem occurs because the function GetLine calls a
function named strlen in the standard UNIX string library.
The linker/loader thinks that this function is referring to the global
variable named strlen instead of the function in the library.
The correct way to avoid such problems is to make your global
variables static when they are not used by functions in other
files. (If you have to use global variables from other files, then
you have to be very careful about what you name them.) The following
program and sample run shows that the
weird error goes away when the global variables are declared to be
- We reviewed the previous lecture on pointers.
In this program and sample run,
we use dereferenced integer pointers in integers expressions just like
any other integer variable.
- We use pointers in this program to
pass integer variables to a function by reference. The function
stores the number of hours and minutes in the variables whose
addresses are stored in the parameters.
- We examined parameter passing by reference in greater detail
in the next example. Program and sample
- Using parameters passed by reference makes it possible
to write a function that swaps the contents of two variables
Program and sample run.
Mon Nov 27 17:00:23 EST 1995
Richard Chang, firstname.lastname@example.org