Sections 0101, 0102, 0103 and Honors, Fall 1995
Tuesday October 10, 1995
Assigned Reading: 5.4 - 5.5
Handouts (available on-line): none
- Traced through another example of function calls from a previous
The question and
- Reviewed the importance of using function prototypes.
Here's a program that doesn't use
function prototypes. Strange output
is produced. The modified program
works correctly when the function prototype for add3 is put in
(sample run of the corrected program).
- When we use a function we should be careful to call the function
with parameters that are of the same type as declared in the
function's prototype. Here's a program
that violates this dictum; it lets the C compiler do the type
conversion. It works (see sample run),
but I consider this very poor programming style. If the C compiler
cannot convert the type of the actual parameter to the type
of the formal parameter, as in this program,
the compiler should give a compile time
- A function that computes the value of a raised to power b.
Using the function tested in the previous step, we write
that rounds numbers within a given precision.
The meaning of functions like floor can be found
in the Unix manual pages for floor
by typing man floor.
If you typed man exp in UNIX, you would have noticed that there
is already a function (called pow) that computes a raised to the
power b. The manual entry for
"exp" begins with an explanation of "exp" for FORTRAN, ignore
It is easy to modify our program which rounds real numbers so that
it uses the pow function from the math library. We simply
have our function call pow.
- Returned Quiz 1.
Thu Oct 12 08:48:53 EDT 1995
Richard Chang, email@example.com