Thread: C Program Header File
i trying learn header files. here simple program multiplies 2 numbers together:
multiply.c
header.hcode:#include <stdio.h> #include "header.h" int main (int argc, char *argv[]) { int x = 0; int y = 0; scanf ("%d", &x); scanf ("%d", &y); printf("%d\n", multiply (x, y); return 0; }
multiplyfunc.ccode:int multiply (int num1, int num2);
i compile code with:code:#include "header.h" int multiply (int num1, int num2) { return num1 * num2; }
this works great, however, trying realize point of header files, because got rid of #include "header.h" in multiply.c , multiplyfunc.c , program still compiled , linked fine , able run program. should rid of header.h since works fine without it? if so, in case use header file?code:gcc multiply.c multiplyfunc.c -o multiply
header files supposed give set of methods or classes, not declarations. basically, don't need them unless you've big class or lot of functions prettier if moved file.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] C Program Header File
Ubuntu
Comments
Post a Comment