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 7589439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:09:34+00:00 2026-05-30T20:09:34+00:00

Possible Duplicate: What should main() return in C/C++? What does main return? I’ve been

  • 0

Possible Duplicate:
What should main() return in C/C++?
What does main return?

I’ve been wondering this for a while: what is the purpose of a return 0; statement at the end of the main() function?

I know that a return statement at the end most functions returns a value to the function which called it. However, as I understand it, the main function is the starting and ending point of the program, so I’m a little confused as to why it has a return type at all?

main()
{
  //code goes here

  return 0; // <-- what is the point of this return statement?
}

edit: I’m pretty new to programming (first year computer science student) and after looking at some of the answers it sounds like the return statement is used to tell the caller of the function if it has completed successfully. Other than the OS and command line, is there anything else that can call a main function? thanks for the quick answers =)

  • 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-30T20:09:36+00:00Added an answer on May 30, 2026 at 8:09 pm

    It’s used to tell the environment running the program whether or not it completed successfully. This is important for command-line tools if you want to run them from scripts.

    You should return zero or EXIT_SUCCESS on success, or EXIT_FAILURE on failure – the constants are defined in <cstdlib>.

    If you like, you can omit the return statement from the end of main – the result will be the same as returning zero. This is a special case for main only – you must still return a value from any other non-void function.

    Other than the OS and command line, is there anything else that can call a main function?

    No – C++ specifically prohibits calling main from within the program.

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

Sidebar

Related Questions

Possible Duplicate: When should I do certain SQLite operations on another thread(not the main
Possible Duplicate: Why is the `gets' function is dangerous? Why should not be used?
Possible Duplicate: What is the proper declaration of main? A little while ago I
Possible Duplicate: Where should I call Free() function? When I used valgrind --leak-check=full --show-reachable=yes
Possible Duplicate: LINQ to SQL: Return anonymous type? This is my code: class B
Possible Duplicate: Error handling in C code What return value should you use for
Possible Duplicate: Should Usings be inside or outside the namespace sa1200 All using directives
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there
Possible Duplicate: What should a good BugTracking tool be capable of? Although there is
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on

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.