Defining a Function
1. int gcd(int u, int v)
2. {
3. int temp;
4. temp = u % v;
5. u = v;
6. v = temp;
7. return (v);
8. }
In this function, observe that:
1.
Line 1 is a function header and by rule a function header is always formal and the
arguments within it are known as formal arguments or dummy arguments.
2.
The arguments that are passed from main( ) are known as actual arguments. The actual
arguments may be constants, variables, or more complex expressions.
3.
Each actual argument must be of the same type as its corresponding formal argument.
4.
It is the value of each actual argument that is transferred into the function and assigned to
the corresponding formal argument.
5. If the return type of the function is not specified, then by default it is assumed to be of type
int.
6. Formal arguments cannot be constants or expressions.
7. Rules for naming a function are the same as for variable names.
8. The return type in the main or in the function must be of the same type.
9. The function is known as a
called function
while the main( ) function that calls it is known as a
Do'stlaringiz bilan baham: |