0

Is there any difference if I use return 0 instead of:

system("PAUSE");
return EXIT_SUCCESS

Here is the script:

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!";

system("PAUSE");
return EXIT_SUCCESS;
}
Biffen
  • 6,249
  • 6
  • 28
  • 36
  • [related](https://stackoverflow.com/a/461855/10957435) –  Aug 06 '19 at 08:53
  • `system("PAUSE")` is irrelevant here. – juanchopanza Aug 06 '19 at 08:54
  • if i only use "return 0" as the end of the script, there will be the same result even system("PAUSE") is omitted –  Aug 06 '19 at 09:05
  • I prefer using `return EXIT_SUCCESS;` or `return EXIT_FAILURE;` because it conveys the intended meaning. In practice, my position is in the minority, and you also have to remember to `#include `. Also, in C++, you can omit the return in the `main` routine, and that will do an implied `return 0;`, which is fairly common practice. – Eljay Aug 06 '19 at 11:31

1 Answers1

2

EXIT_SUCCESS is a constant for the successfull execution of the program. See here

#define EXIT_SUCCESS    0   /* Successful exit status.  */

The command system("PAUSE") generate a command line pause (only for Windows!). So this command is indepentend of your return 0 or return EXIT_SUCCESS.

Kampi
  • 1,798
  • 18
  • 26
  • so.. is system("pause") really necessary during coding?I think it can be omitted –  Aug 06 '19 at 09:01
  • Please see [this](https://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong) discussion for an answer. `system("pause")` is windows only (so there is no linux or other OS equivalent) and a bad practice. – Kampi Aug 06 '19 at 09:04
  • `return 0;` and `return EXIT_SUCCESS;` are both required to return an appropriate value that indicates success. That's usually 0, but it doesn't have to be; it depends on the system's convention. The other portable return value is `EXIT_FAILURE`. – Pete Becker Aug 06 '19 at 12:48
  • But this shouldn´t be a problem when you use the `stdlib.h` or is this wrong? Sure you can´t use this macro when no `stdlib.h` is available for your target system, so you have to check if the correct return value is `0` or something else. – Kampi Aug 06 '19 at 12:52