// Writing a function example
#include
<iostream>
int square( int ); // function prototype
int main()
{
cout << square( x ) << " “ << endl; // function call
return 0;
// indicates successful termination
} // end main
// square function definition
returns square of an integer
int square( int y
) // y is a copy of argument to
function
{
return y * y; // returns square of y as an
int
} // end function square
Parentheses () cause function
to be called. When done, it returns the result.
Function prototype: specifies data types of
arguments and return values. square
expects an int,
and returns an int.
The function definition contains the actual code to
run when the square is called