DAY25
Monday, 09 July 2012
Today we might talk about:
-
Computing the minimum of two integers using a function.
-
Computing the minimum of a float vector using a function.
-
Computing the minimum of a double matrix using a function.
-
Computing the greatest common divisor (GCD) of two integers using a function.
-
passing an array to a function as input;
-
passing an array value to a function as input;
-
passing an array to a function, which fills up the array with output information;
-
passing arrays (vector or a matrix) whose size is not a constant;
(look at the matrix_min() example. You can't do this so easily
in C++, by the way!)
-
a puzzle: why array arguments can be changed but scalar arguments cannot be.
Programs and functions we might talk about:
-
fibonacci.c,
a program which passes an array to a function; the function changes the
values in the array, using it to send output information.
-
int_min.c,
a program which calls a function to compute the minimum of two integers.
-
matrix_min.c,
a function which computes the minimum of the entries in a (double) matrix.
-
p8.6.c, a program to compute the greatest common divisor
or GCD of two integers;
-
puzzle.c, tries to sort 3 integers by calling
a function. They are sorted inside the function, but when the function
returns, they aren't sorted. What's going on? If we pass an array instead
of three scalar values, the sorting "sticks". The explanation has to do
with the difference in how scalar and array input arguments are handled.
If scalar arguments really do need to be modified, they have to be passed
as pointers (which we haven't covered yet).
-
vector_min.c,
a function which computes the minimum of the entries in a (float) vector.
Last revised on 02 July 2012.