C - Function Prototype

A C function prototype is a declaration that provides information about a function's name, its return type, and the number and types of its parameters. It typically appears before the function definition or before any function calls in the code to inform the compiler about the function's signature. This helps the compiler perform type checking and ensures that the function is used correctly.

Function Prototype Syntax:

return_type function_name(parameter_type1 parameter1, parameter_type2 parameter2, ...);
    
  • return_type: The data type of the value that the function returns. Use void if the function doesn't return a value.
  • function_name: The name of the function.
  • parameter_type1, parameter_type2, etc.: The data types of the function's parameters. If the function takes no parameters, use void.
Example:

// Function prototype
int add(int a, int b);

int main() {
    int result = add(5, 3); // Function call
    return 0;
}

// Function definition
int add(int a, int b) {
    return a + b;
}