can i put anything for the "return" in the main function?

#include <iostream>

class CHighScore
{
public:
char mcaName[25];
int miScore;
};

int main()
{
using namespace std;
CHighScore qHighScore = {"Hwllo World", 100000};
cout << qHighScore.mcaName << " " << qHighScore.miScore << endl;
return EXIT_SUCCESS;
}


Can i put anything in the "return" in the main function?
I change the "return EXIT_SUCCESS;" to "return 0;", and it still works. But i need more explanation about this. Would it have any negatif effect to the code that i run if u just put "return 0;" all the time?
Last edited on
Well, from what I've read, every time the int main() returns 0, it means the program was successful and will exit.

I would think that return 0 would work all the time but I'm still a beginner.
Same here. Still a beginner to. This is my first semester using C++. Before this, i use C and the main function was Void. Not int. Thank you for the respond.
Last edited on
I'm also a beginner, but I think it has to do with situations where an outside program calls this one. "return 0" tells the calling function that the program ran without problems.
EXIT_SUCCESS is defined as 0, so there's no difference except that the former is more verbose.
In C++ (but not in C before C99), main automatically returns 0 when it reaches the end, so no return statement is necessary here.

Before this, i use C and the main function was Void. Not int.

In C, main has to return int as well. Everything else is not standard.
Last edited on
@Gaminic, thanx for the respond.

@Athar, Thanx for the explanation. It helps.
In c++ the main function should return an int (not void).
if there is no specific return statement, then this will be the same a return 0;

As the return type is integer, then any integer value can be returned - although a return of 0
is common usage to indicate successful program termination, and 1 to mean program failure (these arethe same as the EXIT_SUCCESS and EXIT_FAILURE defines in the standard library.

The return value from the program is passes back to the operating system.
It can be used in DOS batch files ERORLEVEL command (but the ERRORLEVEL test can only test values between 0 and 255 IIRC)

BUT as in all cases like this - refer to the C++ standards document.
@questgulkan, thanx. Your explanation is abit complicated for me, but i understant what your saying.
Last edited on
Topic archived. No new replies allowed.