Thread: how difference between including the header file and source file in main file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    kotin
    Join Date
    Oct 2009
    Posts
    132

    how difference between including the header file and source file in main file

    Hi,

    i have two files. 1.c and 2.h like below


    2.h file

    Code:
    int fun()
    {
            printf ("hai how are you\n");
            return 0;
    }
    1.c file

    Code:
    #include<stdio.h>
    #include"2.h"
    int i;
    int j;
    int main()
    {
            int fun();
            printf ("%d\n",i);
            fun();
            printf ("%d\n",i);
    }
    if run the above program by using #cc 1.c , i should get the output as

    "0
    hai how are you
    0".

    if i rename the 2.h to 2.c and reflect the same change in include file on 1.c , then also i get the same output.


    actualy what is the correct procedure?

    in which condition i include .h file and in which condition i need to include .c file?

    i would appreciate any help.
    Last edited by nkrao123@gmail.; 09-12-2011 at 10:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. header file including
    By kapil1089thekin in forum C Programming
    Replies: 3
    Last Post: 01-16-2011, 08:31 AM
  2. including header file
    By Delia in forum C Programming
    Replies: 1
    Last Post: 03-20-2010, 04:52 PM
  3. Replies: 3
    Last Post: 02-10-2009, 02:51 PM
  4. Including header file with in the header file
    By Arafat_211184 in forum C Programming
    Replies: 13
    Last Post: 12-19-2005, 10:03 AM
  5. Replies: 4
    Last Post: 12-14-2005, 02:21 PM