Node:Parameters in function prototypes, Next:, Previous:Parameters, Up:Parameters

Parameters in function prototypes

Note that in the function prototype for calculate_bill, the parameter names were completely omitted. This is perfectly acceptable in ANSI C, although it might be confusing to someone trying to understand your code by reading the function prototypes, which can be in a separate file from the functions themselves. For instance, in the code example above, the function prototype for calculate_bill looks like this:

int calculate_bill (int, int, int);

You may include parameter names in function prototypes if you wish; this is usually a good idea when the function prototype is significantly separated from the function definition, such as when the prototype is in a header file or at the top of a long file of function definitions. For example, we could have written the prototype for calculate_bill thus:

int calculate_bill (int diner1, int diner2, int diner3);

Parameter names in a function prototype do not need to match the names in the function's definition; only their types need to match. For example, we can also write the function prototype above in this way:

int calculate_bill (int guest1, int guest2, int guest3);

As usual, it is a good idea to use mnemonic names for the parameters in a function prototype, as in the last two examples. 1 Thus, the function prototype below is not as helpful to the person reading your code as the last two examples are; it might just as well have been written without variable names at all:

int calculate_bill (int variable1, int variable2, int variable3);


  1. That is, unless you are competing in The International Obfuscated C Code Contest.