Skip to main content

Function prototyping

Short answer

A function prototype declares return type, name, and parameter types before use (e.g., float avg(int, int);). It enables compiler argument checking and allows calling functions defined later.

What is the meaning of function prototyping?

Function prototyping means declaring a function before it is used, to tell the compiler its name, return type and the number and types of its parameters. The prototype ends with a semicolon and has no body.

Syntax: return_type function_name(parameter_types);

For example float average(int, int);

Use:

  • lets the compiler check each call for the correct number and types of arguments;
  • allows calling a function that is defined after main();
  • prevents wrong return-type assumptions.
#include <stdio.h>
float average(int, int);           /* function prototype */
int main(void)
{
    printf("Average = %.1f\n", average(7, 10));
    return 0;
}
float average(int a, int b)
{
    return (a + b) / 2.0f;
}

Output:

Average = 8.5

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 6 questions →