Calling programs pass information to called functions in “actual arguments.” The called functions access the information using corresponding “formal arguments.”
When a function is called, the following tasks are performed:
void Func( int i ); // Function prototype
...
Func( 7 ); // Execute function call
The conceptual initializations prior to the call are:
int Temp_i = 7;
Func( Temp_i );
Note that the initialization is performed as if using the equal-sign syntax instead of the parentheses syntax. A copy of i
is made prior to passing the value to the function. (For more information, see Initializers and Conversions, Initialization Using Special Member Functions, and Explicit Initialization .
Therefore, if the function prototype (declaration) calls for an argument of type long, and if the calling program supplies an actual argument of type int, the actual argument is promoted using a standard type conversion to type long (see Chapter 3, Standard Conversions).
It is an error to supply an actual argument for which there is no standard or user-defined conversion to the type of the formal argument.
For actual arguments of class type, the formal argument is initialized by calling the class’s constructor. (See Constructors for more about these special class member functions.)
The following program fragment demonstrates a function call:
void func( long param1, double param2 );
void main()
{
int i, j;
// Call func with actual arguments i and j.
func( i, j );
...
}
// Define func with formal parameters param1 and param2.
void func( long param1, double param2 )
{
...
}
When func
is called from main, the formal parameter param1
is initialized with the value of i
(i
is converted to type long to correspond to the correct type using a standard conversion), and the formal parameter param2
is initialized with the value of j
(j
is converted to type double using a standard conversion).