It was my understanding that in order to use a function declared in a header file and defined in a matching source file, said header file must be included before main(). So why does the following compile and run just fine using:
gcc -o hello hellomain.c hello.c
hellomain.c
int main(int argc, char *argv[])
{
helloPrint();
return 0;
}
hello.h
#ifndef hello_h
#define hello_h
void helloPrint();
#endif
hello.c
#include <stdio.h>
void helloPrint()
{
printf("Hello, World!");
}
This is obviously a very simplified example but it illustrates my question; why don't I have to include "hello.h" in "hellomain.c"? Thanks!