Why return 0 from main () to a C program?

When writing a program in C / C ++, in particular, with the latest compilers, why do we need to return an integer from the main () method? Like int main (), we return "return 0" from it. So what is the reason for this?

+4
source share
5 answers

It returns 0 to the OS to inform the OS that your program completed successfully.

+3
source

The return value of main () becomes the process exit status. Traditionally, a zero exit status usually means “OK”, while any nonzero value indicates some error. This is similar to how many system calls also return zero or an error code.

. , : main() C ++?

+11

, main() int main(). , , , script . 0 " ". , .

+8

int, main(), , "". main() . , , . , , .

+4

. main 0, EXIT_SUCCESS?.

main() , . main() .

C90/C99/++ 98:

EXIT_SUCCESS,      .

In other words, a specific meaning indicates success.

+2
source

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


All Articles