tags:

views:

38

answers:

1

Possible Duplicate:
What are the point of header files in C?

what is the usefulness in creating our own header file while doing a project??

A: 

Header files promote code reuse. There by less maintenance etc.

You can put function declarations, macros, any variables etc. This is how one builds Libraries in C.

e.g:

btree.h

#ifndef BSTREE_H
#define BSTREE_H

#define TRUE 1
#define FALSE 0

typedef struct node
{   
    int data;
    struct node *left;
    struct node *right;
} NODE;

/* BSTREE Manipulation Functions */
NODE *new_node(int data); 

btree.c

#include "bstree.h"

NODE *new_node(int data)
{
    NODE *nnode = malloc(sizeof(NODE));
    if(nnode)
    {
        nnode->data = data;
        nnode->left = NULL;
        nnode->right = NULL;
    }
    return nnode;
}

}
int main()
{
    NODE *root = new_node(1);
}

This is a short code for Binary Search Tree (BST). Now one could use btree.h in other C files which need BST implementation.

MovieYoda