section 1.8: Arguments -- Call by Value

page 27

If, on the other hand, you are not used to other languages such as Fortran, these call-by-value semantics may not be surprising (any more than anything else in C which is new to you).

Even though you can modify a parameter in a function (i.e. treat it as a ``conveniently initialized local variable''), you certainly don't have to, especially if (as is often the case) you'll need an unmodified copy of the parameter later in the function.

page 28

Don't worry too much about the exception mentioned for arrays--there are a number of exceptions for arrays, and we'll have much more to say about them later. But be aware that we are deliberately glossing over a few details here, and they are details which will become important later on. (In particular, the statement on page 27 that ``the called function cannot directly alter a variable in the calling function'' may not seem to be true for arrays, and this is what the authors mean when they say that ``The story is different''. We'll be seeing several functions which return things--usually strings--to their callers by writing into caller-supplied arrays. In chapter 5 we'll learn how this is possible. If this discrepancy wouldn't have bothered you now, pretend I didn't mention it.)


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback