In the third last paragraph at page number 26 of the ebook “The C Programming Language” the author(s) say,
“We will generally use parameter for a variable named in the parenthesized list in a function. The terms formal argument and actual argument are sometimes used for the same distinction.”
And in the hard copy of the book that I am having, on the second last paragraph of page number 25 the author(s) say,
“We will generally use parameter for a variable named in the parenthesized list in a function definition, and argument for the value used in a call of the function. The terms formal argument and actual argument are sometimes used for the same distinction.”
If I understand it correctly, it means whatever the value(or variable) is used in the call of a function, that is called argument. And whatever is written in the paranthesis of the definition of a function, that is called parameter. E.g. in the following code:
#include<stdio.h>
int func(int j)
{
return j;
}
main()
{
int k=5;
printf("The argument = %d", func(k));
}
the parameters are declared by the line int func(int j)
. The argument given, through which main()
and func(int j)
communicate is k
.
Now, on the page number 30 of the book(both, the ebook and the hard copy) the authors state,
“
main
andgetline
communicate through a pair of arguments and a returned value. In
getline
, the arguments are declared by the line
int getline(char s[], int lim);"
As I understand, char s[]
and int lim
are parameters, because they are written in the definition of the function getline
, not in the call of that function, so my question is,
Why have the authors used the word argument in the second paragraph of page number 30?
7
English (and I presume other languages as well) has a lot of words which can be used in a generic sense, but are no longer correct in a context which requires more distinction. For example, you can use the word “goose” to refer to a goose of any gender or age when speaking in the more common generic sense, but if a distinction must be made, a male goose is properly called a gander, and a baby goose is properly called a gosling.
“Argument” and “parameter” are two such words. You can use “argument” in a more loose context to refer to either an argument or a parameter, but in certain circumstances it’s helpful to be able to distinguish between them precisely. Those circumstances are rare enough that many programmers don’t learn the distinction for years, if ever.
Don’t ask me why English is that way. It wasn’t designed for ease of parsing.
1
The term “argument” is often used rather loosely to refer to either actual arguments or formal arguments without giving the actual or formal adjective. Most often, the context makes it clear if actual arguments or formal arguments/parameters is meant.
In this case, it should be clear that the authors meant formal arguments or parameters. As to why they didn’t use parameters is pure speculation. It can be a simple oversight or a deliberate choice because it made the text flow better.
5
First, let’s recap:
- “parameter = the variable’s name”
- “argument = the expression we pass to the function”
Note too that “argument” isn’t the variable’s name. Therefore, it is everything else. Figuratively speaking, you can think of “argument” as a pipe/line. A line that connects the text in the source code holding the “actual argument” with the text in the source code naming the “formal argument”.
This pipe has a type. It represent a C cast. A cast is defined by the source type and the destination type.
When they tell you that “the arguments are declared by the line int getline(char s[], int lim)
” they tell you that here’s the definition of the pipe (which is “argument”): its target type is “char []” (and source type can be anything).
3