1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Why do we use the header file in C

Discussion in 'Programming' started by rambo, Sep 6, 2007.

  1. #1
    Why do we use the header file in C.

    #include<stdio.h>
    void main()
    {
    printf("Hello");
    }

    OR

    void main()
    {
    printf("Hello");
    }

    both returns same output then why do we use #include<stdio.h>
     
    rambo, Sep 6, 2007 IP
  2. Coder

    Coder Banned

    Messages:
    311
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Coder, Sep 6, 2007 IP
  3. rambo

    rambo Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    naa it doesnt solve the query....
     
    rambo, Sep 7, 2007 IP
  4. amf-flt

    amf-flt Active Member

    Messages:
    100
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    In the situation you list, there's no real benefit unless you have strict rules on.

    However, if you were to try to use, say, the open or stat routines, you wouldn't get them to compile without the header file included.
     
    amf-flt, Sep 7, 2007 IP
  5. comboy

    comboy Well-Known Member

    Messages:
    328
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #5
    In this case, you don't need to include header. But in the complex source code, you will include header.
     
    comboy, Sep 8, 2007 IP
  6. arcx33

    arcx33 Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Your compiler is just being kind and assuming that printf would be in the standard library and not bugging you about it.

    Turn all warnings on and you will notice that the stdio.h header missing error will be reported.
     
    arcx33, Sep 8, 2007 IP
  7. rambo

    rambo Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    but it requires header files for a c++ program, i mean C++ shows errors but C dont show any errors and the number of lines complied are 400+ in C++ program but in C on few line. like for the above case it would be 4
     
    rambo, Sep 9, 2007 IP