Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:21:35+00:00 2026-05-27T21:21:35+00:00

Possible Duplicate: What is the proper declaration of main? I am working on my

  • 0

Possible Duplicate:
What is the proper declaration of main?

I am working on my C skills and I have noticed that

int main( int argc, char *argv[] )

and

return (EXIT_SUCCESS)

instead of

int main() and return 0

Why is this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:21:35+00:00Added an answer on May 27, 2026 at 9:21 pm

    If you are going to ignore the argument list, it is reasonable and sensible to use:

    int main(void) { ... }
    

    The standards bless this usage, as well as the one with arguments. You get a warning from GCC if you compile with -Wstrict-prototypes and don’t include the void, so I write the void. C++ is different here.

    As for return EXIT_SUCCESS;, there seems to be little benefit to it in general; I continue to write return 0; at the end of a main() function, even though C99 permits you to omit any return there (and it then behaves as if you wrote return 0;).

    ISO/IEC 9899:1999

    §5.1.2.2.1 Program startup

    ¶1 The function called at program startup is named main. The implementation declares no
    prototype for this function. It shall be defined with a return type of int and with no
    parameters:

    int main(void) { /* ... */ }
    

    or with two parameters (referred to here as argc and argv, though any names may be
    used, as they are local to the function in which they are declared):

    int main(int argc, char *argv[]) { /* ... */ }
    

    or equivalent;9) or in some other implementation-defined manner.

    9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
    char ** argv, and so on.

    §5.1.2.2.3 Program termination

    ¶1 If the return type of the main function is a type compatible with int, a return from the
    initial call to the main function is equivalent to calling the exit function with the value
    returned by the main function as its argument;10) reaching the } that terminates the
    main function returns a value of 0. If the return type is not compatible with int, the
    termination status returned to the host environment is unspecified.

    10) In accordance with §6.2.4, the lifetimes of objects with automatic storage duration declared in main
    will have ended in the former case, even where they would not have in the latter.

    §7.20.4.3 The exit function

    ¶5 Finally, control is returned to the host environment. If the value of status is zero or
    EXIT_SUCCESS, an implementation-defined form of the status successful termination is
    returned. If the value of status is EXIT_FAILURE, an implementation-defined form
    of the status unsuccessful termination is returned. Otherwise the status returned is
    implementation-defined.

    Aside: Note that §5.1.2.2.3 clearly indicates that the C standard allows an implementation to permit return types for main() other than int (unlike the C++ standard, which expressly forbids a return type other than int). However, as Jens rightly points out, a non-int return type from main is only allowed if the implementation explicitly documents that it is allowed, and the documentation will probably place limits on what is allowed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the proper declaration of main? A little while ago I
Possible Duplicate: What is the proper declaration of main? Without citing any code in
Possible Duplicate: Proper Use of yield return What is the use of the yield
Possible Duplicate: C# - Proper Use of yield return What can be a real
Possible Duplicate: Does anyone have a good Proper Case algorithm I am currently in
Possible Duplicate: What is the proper way to return an object from a C++
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: What's the proper way to minimize to tray a C# WinForms app?
Possible Duplicate: ASP.NET “special” tags Is there a proper name for <%...> in ASP.NET,
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.