If a function is to use arguments, it must declare variables that will accept the values
of the arguments. These variables are called the formal parameters of the function. They
behave like any other local variables inside the function. As shown in the following
program fragment, their declarations occur after the function name and inside
parentheses:
/* Return 1 if c is part of string s; 0 otherwise */
int is_in(char *s, char c)
{
while(*s)
if(*s==c) return 1;
else s++;
return 0;
}
The function is_in() has two parameters: s and c. This function returns 1 if the character
specified in c is contained within the string s; 0 if it is not.
You must specify the type of the formal parameters by declaring them as just shown.
Then you may use them inside the function as normal local variables. Keep in mind that,
as local variables, they are also dynamic and are destroyed upon exit from the function.
As with local variables, you maymake assignments to a function's formal parameters
or use them in any allowable expression. Even though these variables receive the value of
the arguments passed to the function, you can use them like any other local variable.
of the arguments. These variables are called the formal parameters of the function. They
behave like any other local variables inside the function. As shown in the following
program fragment, their declarations occur after the function name and inside
parentheses:
/* Return 1 if c is part of string s; 0 otherwise */
int is_in(char *s, char c)
{
while(*s)
if(*s==c) return 1;
else s++;
return 0;
}
The function is_in() has two parameters: s and c. This function returns 1 if the character
specified in c is contained within the string s; 0 if it is not.
You must specify the type of the formal parameters by declaring them as just shown.
Then you may use them inside the function as normal local variables. Keep in mind that,
as local variables, they are also dynamic and are destroyed upon exit from the function.
As with local variables, you maymake assignments to a function's formal parameters
or use them in any allowable expression. Even though these variables receive the value of
the arguments passed to the function, you can use them like any other local variable.
No comments:
Post a Comment