What is the Difference Between Function Prototype and Function Definition in C?

🆚 Go to Comparative Table 🆚

The main difference between a function prototype and a function definition in C lies in the function body. A function prototype specifies the function's name, return type, and parameters, while a function definition includes the function body, which contains the actual code for the function.

Function Prototype:

  • Also known as a function declaration or function interface.
  • Specifies the function's name, return type, and parameters.
  • Provides the function's signature without including the function body.
  • Used as a declaration to inform the compiler about the function's existence.

Function Definition:

  • Includes the function's name, return type, parameters, and the function body.
  • Provides the actual code for the function's implementation.
  • Tells the compiler how the function does what it does.

In summary, a function prototype informs the compiler about the existence and signature of a function, while a function definition provides the full details of the function, including its implementation.

Comparative Table: Function Prototype vs Function Definition in C

The difference between a function prototype and a function definition in C is as follows:

Function Prototype Function Definition
Specifies the function name, return type, and parameters Includes the function name, return type, parameters, and the function body
Does not include the function's core Contains the function's core with local variables and statements
Typically appears at the top of a source file or in a header file Typically appears below the prototype in a source file

A function prototype is used to declare a function before it is defined, providing the compiler with information about the function's name, return type, and parameters. This allows other parts of the code to use the function before its implementation is available. On the other hand, a function definition includes the function's core, which contains the local variables and statements that determine the function's behavior.