C Language | Functions | Function Declarations
A function declaration tells the compiler a function’s name, return type, and parameter types without defining its body.
Function Prototypes
Declare a prototype before calling a function whose definition appears later.
return_type function_name(parameter_list);
#include <stdio.h>
void CharLoop(char chMark, int iNum);
int main(void) {
CharLoop('*', 30);
printf("\n---\n");
CharLoop('*', 40);
printf("\n");
return 0;
}
void CharLoop(char chMark, int iNum) {
int iCount;
for (iCount = 0; iCount < iNum; iCount++)
printf("%c", chMark);
}
Modern code should use prototypes. For a function with no parameters, write void explicitly.
void Function(void);
Writing void Function(); does not declare a no-parameter prototype in C. It declares a function with unspecified parameters.
Omitting Parameter Names
Names are optional in a prototype because only the types are required.
void Function(int, char, double);
void CharLoop(char chMark, int);
Parameter names are still useful when they clarify the purpose of each value.