when i'm reading some tutorial in C programming,all of them said that we need to put only structure type declarations, function prototypes, and global variable extern declarations, in the .h file; and for the function definitions and global variable definitions and initializations we need to put them in the .c file.
but when i try to put the content of the function in the header file it works fine. if it works fine why we must not use it ?
in the sum.h :
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
#include<stdio.h>
#include<stdlib.h>
int sum(int a,int b)
{
return a+b;
}
#endif // HEADER_H_INCLUDED
int the main.c:
#include "sum.h"
int main()
{
printf("%d\n",sum(1,2));
return 0;
}