Function Prototypes and Headers
A prototype declares a function before it is defined. Headers (.h files) hold prototypes and types, and .c files hold the definitions. Include guards stop double inclusion.
Example
#include <stdio.h>
int add(int a, int b);
void greet(const char *name);
int main(void) {
printf("%d\n", add(2, 3));
greet("Ada");
return 0;
}
int add(int a, int b) { return a + b; }
void greet(const char *name) { printf("Hello %s\n", name); }Result
5 Hello Ada
Exercise
End a prototype.
int add(int a, int b)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.