Page t054, go to INDEX,
PREVIOUS, INDEX
const Function Argument
Consider
void f (int i, float x, const float *a)
{
i = 100;
x = 101.0 * a[0]; /* OK */
a[0] = 0.0; /* WRONG */
}
int main ()
{
int j = 1;
int k = 2;
float y[] = {3.0, 4.0, 5.0};
. . .
f (j, k, y);
. . .
}
- a const argument tells user of function that his
data wouldn't be changed
- the const is enforced when attempting to compile
function
C Course, 22-jan-1997,
Peter Klok,
pfk@hef.kun.nl