Formal and Actual Parameters
#include <stdio.h>
/* subprogram prototypes - declarations */
int function1(int, float);
/* 2 formal parameters of type int, float */
/* an integer value is returned */
float function2(int, float, int);
/* 3 formal parameters of type int, float, int */
/* a float value is returned */
int function3(char, char);
/* 2 formal parameters of type char, char */
/* an int value is returned */
void function4(char, int);
/* 2 formal parameters of type char, int */
/* nothing is returned - procedure */
void function5(void);
/* no formal parameters, i.e. void */
/* nothing is returned - procedure */
void function6(int *);
/* 1 formal parameter of type address of an int */
/* nothing is returned - procedure */
int main(void)
{
int num1, num2 = 4;
float val1, val2 = 27.8;
char let1, let2 = 'a';
num1 = function1(2, 3.4);
/* actual parameters are the values 2, 3.4 */
val1 = function2(num1, val2, 3);
/* actual parameters are the values of num1, val2, and the value 3 */
num1 = function3(let2, 'c');
/* actual parameters are the value of let2 and the value 'c' */
function4(let2, num1);
/* actual parameters are the values of let2 and num1 */
function5();
/* there are no actual parameters */
function6(&num1);
/* actual parameter is the address of the variable num1 */
return (0);
}
/* function header - 2 formal parameters named number, value of type int,
float respectively. Return type is int. */
int function1(int number, float value)
{
int num1;
num1 = value; /* this truncates the float to an integer */
return (number * num1);
}
/* function header - 3 formal parameters named number1, value and number2 of
type int, float, int. Return type is float. */
float function2(int number1, float value, int number2)
{
return (3.4 * 4);
}
/* function header - 2 formal parameters named letter1 and letter2 of type
char, char. Return type is int */
int function3(char letter1, char letter2)
{
return (1);
}
/* function header - 2 formal parameters named letter and number of type
char, int. Return type is void - this functions acts like a
procedure */
void function4(char letter, int number)
{
return; /*note: the return statement returns nothing and is NOT needed*/
}
/* function header - 0 formal parameters. Return type is void - this
functions acts like a procedure */
void function5(void)
{
}
/* function header - 1 formal parameter of type address of an integer. Return
type is void - this functions acts like a procedure */
void function6(int *number)
{
}