VOOZH about

URL: https://www.geeksforgeeks.org/cpp/return-0-vs-return-1-in-c/

⇱ return 0 vs return 1 in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

return 0 vs return 1 in C++

Last Updated : 23 Jul, 2025

The Return statement in C/C++:

There are two scenarios in which return statements will be used:                  

:

  • In this case, the return statement stops the execution of the program, and 0 or 1 will denote the execution status.
  • These status codes will be just used as a convention for a long time in C language because the language does not support the objects and classes, and exceptions.
  • return 0: A return 0 means that the program will execute successfully and did what it was intended to do.
  • return 1: A return 1 means that there is some error while executing the program, and it is not performing what it was intended to do.

Important characteristics of the return statement: 

  • If exit with a status other than 0 then, print an error message to stderr.
  • There are different conventions depending on the operating system about return codes.
  • The Operating System may itself terminate the program with specific exit status codes if some invalid operations are performed.

Below is a program to illustrate the use of return 0 and return 1 inside the main function:

Output:
Division by zero is not possible.

Time Complexity: O(1)
Auxiliary Space: O(1)

:

  • C++ treats boolean as a completely separate data type that has only 2 distinct values, i.e., true and false.
  • The values 1 and 0 are of type int and are not implicitly convertible to boolean, that means:
    • returning false from a function.
    • returning true from a function.

Below is a program to illustrate the use of return 0 and return 1 inside the user-defined function:

Output:
You are an adult

Time Complexity: O(1)
Auxiliary Space: O(1)

Conclusion:

Use-casereturn 0return 1
In the main functionreturn 0 in the main function means that the program executed successfully.return 1 in the main function means that the program does not execute successfully and there is some error.
In user-defined functionreturn 0 means that the user-defined function is returning false.return 1 means that the user-defined function is returning true.
Comment