An explicit function declaration specifies a function’s return type and parameter types before the function is called. This allows the compiler to check whether function calls use a compatible interface.
#include <stdio.h>
int divide(int numerator, int denominator);
int main(void)
{
int result = divide(20, 4);
printf("Result = %d\n", result);
return 0;
}
int divide(int numerator, int denominator)
{
return numerator / denominator;
}
Example Output #
Result = 5
Explanation #
The declaration:
int divide(int numerator, int denominator);
specifies that divide() returns an int and accepts two int parameters. It appears before the function call, so the compiler knows the function’s interface when processing the call.
The definition provides the implementation:
int divide(int numerator, int denominator)
{
return numerator / denominator;
}
The function call supplies two arguments:
divide(20, 4);
The function divides 20 by 4 and returns 5.
Explicit Declaration Forms #
| Declaration | Meaning |
|---|---|
int getValue(void); |
Returns int and accepts no parameters |
double calculate(double, double); |
Returns double and accepts two double arguments |
void display(const char *message); |
Returns no value and accepts a pointer to constant characters |
int compare(int a, int b); |
Returns int and accepts two integer arguments |
An explicit function declaration is also called a function prototype when it specifies the parameter types. In modern C, declaring functions before use is standard practice, especially when declarations are shared through header files.