Returns the value of the main () function?

Someone please tell me where the main () function of the "C" language returns its value?

+2
source share
5 answers
Function

C mainreturns int ... that int goes into the executable (the parent process, if you do) as an exit status code.

In particular, in most operating systems, exit code 0 means a normal run (no real errors), and non-zero means that a problem has occurred and the program should exit abnormally.

+7
source

The return value if the main () function is used as the program exit status code.

In the shell, you can get the program exit status with $ ?, example:

./prog
exit_status=$?
+4
source

main libery, , . :

return my_return_value;

.

0

: .

main() , .

0

0

C99:

5.1.2.2.3

1 main , int, main exit , main ;

7.20.4.3 exit

5 , . EXIT_SUCCESS, . EXIT_FAILURE, . .

, main .

0

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


All Articles