Thread: int main()

  1. #1
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

    Question int main()

    Why is int main() so much better than void main() when in theory you never go oustide of main to get the return value (or do you??)?

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    The return value goes to the operating system
    So if you add error checking to your program, say if a file cant be opened then return -1, if a file cant be created return -2.
    This can be useful in debugging. When running MSVC++ in the output window at the bottom the return value of your program is shown after it is done running.

  3. #3
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    ah, thanks.

  4. #4
    Registered User alpha561's Avatar
    Join Date
    May 2002
    Posts
    18
    This more or less explains the difference between the two: http://www.cprogramming.com/boardfaq.html#main

    I myself always use int main(void) as per the C standard.
    alpha561

    "You don't want to sell me death sticks"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM