Skip to main content

Thread: C Program Header File


i trying learn header files. here simple program multiplies 2 numbers together:

multiply.c
code:
#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;  }
header.h
code:
int multiply (int num1, int num2);
multiplyfunc.c
code:
#include "header.h"    int multiply (int num1, int num2)  {  return num1 * num2;  }
i compile code with:
code:
gcc multiply.c multiplyfunc.c -o multiply
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?

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

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'