is of type long. • fact is the name of the function. • the function is called with two arguments: The first argument is of int data type. The second argument is of double data type.
int display(int, int) // function prototype// The above function prototype provides details about the return data type, name of the function and a list of formal parameters or arguments. . . Use of void command void type has two important purposes: • To indicate the function does not return a value • To declare a generic pointer.
Chapter Page - - void data type indicates the compiler that the function does not return a value, or in a larger context void indicates that it holds nothing. Notes For Example: void fun(void) The above function prototype tells compiler that the function fun() neither receives values from calling program nor return a value to the calling program. . .
Accessing a function The user-defined function should be called explicitly using its name and the required arguments to be passed. The compiler refers to the function prototype to check whether the function has been called correctly. If the argument type does not match exactly with the data type defined in the prototype, the compiler will perform type conversion, if possible. If type conversion is impossible, the compiler generates an error message.
Example : display() calling the function without a return value and without any argument display ( x, y) calling the function without a return value and with arguments x = display() calling the function with a return value and without any argument x = display (x, y) calling the function with a return value and with arguments . . . Formal Parameters and Actual Parameters or Arguments Arguments or parameters are the means to pass values from the calling function to the called function.
The variables used in the function definition as parameters are known as formal parameters. The constants, variables or expressions used in the function call are known as actual parameters. Using namespace std; int sum ( int x, int y