In the C program if a function is called before it has been declared then the program will generate an error because all the functions within a C program will need to get declared first before they can be called. A C programmer can either create that entire function at the top of the caller or declare it with the function prototype. Function prototype only consists of a function header which is enough for the C compiler to link it to the function which has been declared elsewhere in the program, you will still need to declare that entire function afterward, or else the compiler will report an error as well.
The below C program shows the function prototype in action.
#include<stdio.h> int add(int first, int second); // function prototype int main() { printf("Adding two integers:\n"); printf("%d", add(2, 3)); return 0; } int add(int first, int second) { return first + second; }
The above program will print the following outcome:-
Adding two integers: 5