1 2 3 4 5 6 7 8 9 10

void main (void) {

char message [32]; int m;

m = ReadLine (message, 16);
printf ("%d chars in:%s\n", m, message); m = FetchLine (&message[0], 16); printf ("%d chars in:%s\n", m, message);

}

Function Calls
When you call a function, the actual parameters (arguments)
to the function are copied and placed onto the stack.
Thus the function manipulates copies of the parameters,
not the original arguments themselves. That is, all
function calls in C are call by value
.
To alter a data object in the calling program you
must either return a value from the function
, or
pass the address of the object to the function.

Just to convince you that arguments are copied:

#include <stdio.h>

void look (int a, int b, char c, char d, double f, double g) {
printf ("The address of argument a is %x\n", (int) &a);
printf ("The address of argument b is %x\n", (int) &b);
printf ("The address of argument c is %x\n", (int) &c);
printf ("The address of argument d is %x\n", (int) &d);
printf ("The address of argument f is %x\n", (int) &f);
printf ("The address of argument g is %x\n", (int) &g);
}

January 22, 1999

Page 8

copyright UoA