Question about int and void main()

This is a discussion on Question about int and void main() within the C Programming forums, part of the General Programming Boards category; I just bought the new edition of Let Us C by Y.P. Kanetkar (8th edition). In the examples so far ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    8

    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:

    Code:
    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
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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
    Posts
    8
    Interesting, alright, thanks

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    http://cpwiki.sourceforge.net/Void_main

    Should answer your question.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.

    http://c-faq.com/ansi/voidmainbooks.html
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 06:45 AM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 06:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21