"Bill Cunningham" <no****@nspam.i nvalidwrites:
pgs 140-1 of kandr2 talk about recursion. I tried typing in the code
char by char and couldn't find the bugs so I just read the code and a new
concept to me jumped out. Maybe this is what it means by recursion.
struct tnode *addtree (struct tnode *, char *);
is declared on p 140. But I noticed this on p 141.
struct tnode *addtree (struct tnode *p, char *w);
Can someone explain to me why the parameters are changing here? Would they
need to change more with the program on pages 140-1 ?
In a function declaration that's not part of a function definition,
parameter names are optional. For each parameter, you can specify
either just the type (as in the first example), or the type and the
name (as in the second example).
In a function *definition*, on the other hand, you have to specify the
name, because that's how the body of the function knows how to refer
to the parameters.
A simple example:
int add_one(int); /* this is a legal declaration */
int add_one(int i); /* this is also a legal declaration */
int add_one(int i) /* this is a definition; the name "i" is needed */
{
return i + 1;
}
My advice to you is always to include the parameter names in function
declarations, even though they're not required. Things tend to be
less confusing if the names are always there.
This has absolutely nothing to do with recursion, and I'm at a loss to
understand why you would think that it does. I think you saw the word
"recursion" on a page, saw these two declarations nearby, didn't
understand the declarations, and took a wild guess that they must have
something to do with recursion. These wild guesses of yours are
making learning far more difficult than it needs to be. I have
mentioned this to you several times in the past; it obviously hasn't
done any good.
Recursion means a function calling itself. I'm sure that K&R2
explains it better than I could.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"