Thread: Question about int and void main()

  1. #1
    Registered User
    Join Date
    May 2008

    Question about int and void main() (Solved)

    I just bought the new edition of Let Us C by Y.P. Kanetkar (8th edition). In the examples so far the book has used:

    void main() {}
    When I compile, it gives an error, it should be int not void. I have had the same results using Code::Blocks and terminal on Mac to compile. So why would the book use void?
    Last edited by SkinnyK; 05-13-2008 at 05:10 PM. Reason: Question Answered

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    It's a common misconception usually.
    However, it is correct to use int main.
    The standard says that main must return int. Returning void or anything else from main is non-standard and also therefore undefined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Interesting, alright, thanks

  4. #4
    Registered User
    Join Date
    Oct 2006
    Omaha, Nebraska

    Should answer your question.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If the book goes onto use gets(buffer) or fflush(stdin) then throw it in the shredder or take it back to the store and get your money back. It will be utterly useless to you, and just a cheap piece of fiction for everyone else.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM