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?
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.
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.
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.