
In C++, the return 0; statement simply indicates that the program has completed successfully. It tells the system that the program ran without errors.
For example:
#include
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
} In the code:
The program prints
"Hello, world!".The
return 0;line sends a status code back to the system—0traditionally means success.If something went wrong in your program and you wanted to signal that to the system, you could return a non-zero value like
return 1;.
Why does this matter?
If you're running your program in a larger system or calling it from a script, the return value lets that system know whether the program succeeded. This is useful in automated testing, system monitoring, or when chaining commands in shell scripts.
So while it may seem small, return 0; plays an important role in communicating the outcome of your program to the system.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer