Why should main () return an int?

In most cases, int main() does not return anything, it is not even necessary, since no return will not produce an error. So why should the main return an int? Why is the main impossible?

EDIT: I meant why int main () is standard if usually there is no return ?

+4
source share
4 answers

Other programs may use a return code to determine the success of the application. Zero usually means success.

+7
source

void is possible, but non-standard. The returned int means something to the caller.

+3
source

Just as a function in your program can return values โ€‹โ€‹to indicate its result, main returns to indicate the result of your program.

Also in case int main() returns explicit, the compiler will automatically put return 0

+1
source

Because the standard says so. :-P

(Also, duplicate. ;-))

0
source

Source: https://habr.com/ru/post/1481392/


All Articles