Skip to content
thesarfo

Note

C: Function Prototypes

Declaring a function prototype so a function can be defined anywhere, not just before its first use.

views 0

Though you have to define a function before using it, it’s not entirely true. You can notify the compiler in advance that you’ll be using a function of a certain type that has a certain parameter list, and that way the function can be defined anywhere at all — as long as the function prototype has been declared first.

#include <stdio.h>
int foo(void); /* this is the prototype */
int main(void){
int i;
i = foo();
return 0;
}
int foo(void){ /* this is the definition, just like the prototype*/
return 45;
}