A function is called by giving its name and passing any data to it in the parantheses following the name. If a variable is one of the arguments in a function call, the called function receives a copy of the variable's value.
The commonly used form of a user defined function is Return-type function-declaration { declaration; function statements; }
The first line of the function is called the function header. The opening and closing braces of the function and all statements between these braces constitute the function's body. The function declarator must be included for each function and is of the form
function-name(parameter list)
The parameter list must include the names of parameters and their data types.
Every variable used in a program has a scope, which is either local or global and l3 determined by where the variable's definition statements are placed. A local variable 1s defined within a function and can only be used within its defining function or blocs. A global variable is defined outside a function and can be used in any function following the variable's definition.
Every variable has a storage class. The storage class determines how long the value in the variable will be defined. Automatic variables are local variables that exist only while their defining function is existing. Static variables can be either global or local and retain their values for the duration of a program's execution.
A function can also be passed the address of a variable. By passing addresses, a function has the capability of effectively returning many values.
Review Questions
What is difference between a local variable and a static variable?
Explain about passing values to a function.
Write declaration statements for
(a) a formal argument named price that will be used to accept the address of a double precision number
(b) a formal argument named key that will he used to accept the address of a character.