main() return values and exit()

This is a discussion on main() return values and exit() within the C Programming forums, part of the General Programming Boards category; What exactly is the advantage of using: int main() over using: void main() And if returning a value is better, ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    main() return values and exit()

    What exactly is the advantage of using:
    int main()
    over using:
    void main()
    And if returning a value is better, why? Also - if returning a value holds an advantage, how does it rank with stlib.h's exit(0)?

  2. #2
    and the hat of mystery Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    31,333
    Read some of the topics on this page
    http://www.eskimo.com/~scs/C-faq/s11.html

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well that asnwered my first question - thanks - but is there any difference between exit(0) and return 0?

  4. #4
    and the hat of mystery Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    31,333
    You mean
    http://www.eskimo.com/~scs/C-faq/s11.html

    Better read the whole damn thing

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    There is one big difference between exit and return. Exit will cause the program to terminate even from within a function whereas return does not ( necessarily )...
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

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