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

  • Home
  • SEARCH
  • 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 6990409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:20:45+00:00 2026-05-27T19:20:45+00:00

Possible Duplicate: What is the proper declaration of main? Without citing any code in

  • 0

Possible Duplicate:
What is the proper declaration of main?

Without citing any code in particular, I am looking for an explanation of the below example:

#include <iostream>

int main()
{
    std::cout << "Hello world" << std::endl;
    return 0;
}

I don’t understand what return 0 does. Can you please explain this in as plain English as possible?

  • 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-27T19:20:46+00:00Added an answer on May 27, 2026 at 7:20 pm

    This defines the exit status of the process. Despite being an int, on Unix-like systems, the value is always in the range 0-255 (see Exit and Exit Status). On Microsoft systems you may use 32-bit signed integers as exit codes, which you can check with %ERRORLEVEL%. For portability, I’d recommend sticking to the 0-255 range.

    Here is a trivial example:

    $ cat -n exit_code.cpp 
         1  int main()
         2  {
         3      return 42;
         4  }
         5  
    

    Build:

    $ make exit_code
    g++ exit_code.cpp -o exit_code
    

    Run (in bash):

    $ ./exit_code
    

    Check the exit status:

    $ echo $?
    42
    

    Conventionally, a status of zero signifies success and non-zero failure. This can be useful in shell scripts, and so forth to indicate the level of failure, if any:

    $ ./exit_code
    exit_status=$?
    if [[ ${exit_status} ]] ; then
        echo "The process failed with status ${exit_status}."
    else
        echo "Success!"
    fi
    The process failed with status 42.
    

    Following the comments below…

    In the standard C++ header <cstdlib>, the following macros are defined:

    #define EXIT_SUCCESS 0
    #define EXIT_FAILURE 1
    

    However, the Exit Status section of the GNU C Library documentation, describing the same macros, sagely states:

    Portability note: Some non-POSIX systems use different conventions for exit status values. For greater portability, you can use the macros EXIT_SUCCESS and EXIT_FAILURE for the conventional status value for success and failure, respectively. They are declared in the file stdlib.h.

    • 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? I am working on my
Possible Duplicate: What is the proper declaration of main? A little while ago I
Possible Duplicate: C# - Proper Use of yield return What can be a real
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: What Java FTP client library should I use? I am looking for
Possible Duplicate: Are PHP short tags acceptable to use? <?php //Some code ?> or
Possible Duplicate: iOS: How to get a proper Month name from a number? How
Possible Duplicate: How to decode Unicode escape sequences like “\u00ed” to proper UTF-8 encoded
Possible Duplicate: How to decode Unicode escape sequences like “\u00ed” to proper UTF-8 encoded

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.