|
If a name that has not been described before appears in an expression and is followed by the left parenthesis,
it will be contextually considered as the name of a function.
function_name (x1, x2,..., xn)
Arguments (formal parameters) are passed by value, i.e.,
each expression xl, . . . , xn is calculated, and the value is passed to the function. The order of expressions calculation
and that of values loading are guaranteed. During the execution, the system checks the number and type of arguments given to the function.
Such way of addressing to the function is called a value call. Function call is an expression thy value of which is the value returned by the function.
The function type described above must correspond with the type of the returned value. The function can be declared or described in any part of the program
on the global scope, i.e., outside other functions. The function cannot be declared or described inside of another function.
Examples:
int start()
{
double some_array[4]={0.3, 1.4, 2.5, 3.6};
double a=linfunc(some_array, 10.5, 8);
//...
}
double linfunc(double x[], double a, double b)
{
return (a*x[0] + b);
}
At calling of a function with default parameters, the list of parameters to be passed can be limited,
but not before the first default parameter.
Examples:
void somefunc(double init,double sec=0.0001,int level=10); // function prototype
somefunc(); // wrong call, the first required parameter must be presented.
somefunc(3.14); // proper call
somefunc(3.14, 0.0002); // proper call
somefunc(3.14, 0.0002, 10); // proper call
When calling a function, one may not skip parameters, even those having default values:
somefunc(3.14, , 10); // wrong call. the second parameter was skipped.
|