A function has two components:
Declarative statement in which the name, return type, and necessary parameters of the function are specified (if any).
Definition, which is merely the function’s body (code to be executed)
The basic structure of a function is,
return_type functionName() { // declaration
// body of the function (definition)
}
It is frequently advised to separate the function’s declaration and definition for code readability and optimization.
This is also the reason why C programmes frequently include function definitions below the main() function and function declarations above it. The code will be better organised and simpler to comprehend as a result.Here’s how to accomplish it.
#include <stdio.h>
// Function declaration
void func();
int main()
{
func(); // calling the function
return 0;
}
// Function definition
void func()
{
printf("This is the definition part.");
}
Output: This is the definition part.