Thread: Need explanations...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    13

    Need explanations...

    Could you please explain why sometimes in the example the code is in this form

    Code:
    void main()
    {
      printf( "Welcome to C Programming.\n" );
    }
    sometimes

    Code:
    void main(void)
    {
      printf( "Welcome to C Programming.\n" );
    }
    sometimes
    Code:
     int main()
    {
      printf( "Welcome to C Programming.\n" );
    }
    and

    Code:
    main()
    {
      printf( "Welcome to C Programming.\n" );
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Because example code isn't perfect.

    Whenever you see any of the other three example types, convert it to the third form. Even safer would be to convert it to:
    Code:
    int main(void)
    {
        /* ... */
        return 0;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    5
    The main should always return an integer, this is what the C/C++ standard says. void main is not correct in this sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ definitions and explanations help
    By yosimba2000 in forum C++ Programming
    Replies: 10
    Last Post: 06-27-2010, 03:28 AM
  2. Replies: 2
    Last Post: 10-13-2001, 10:22 PM