In a C++ program, should I include the return 0;
thing?
I mean:
This:
#include <iostream>
int main() {
std::cout << "Hello world!";
return 0;
}
or this:
#include <iostream>
int main() {
std::cout << "Hello world!";
}
What is the best practise? Should you include return 0;
?
A simple Google (or search on StackOverflow, etc) would yield useful information. I’ll get you started
2 Likes
Yes you should end main with return(0) if everything went well, or return(-1) if it didn’t. main is a function and is
declared as int main, so it returns an int. you can include cstdlib and use exit(EXIT_SUCCESS) but virtually nobody ever does that. You can return any number it does not have to be 0.