main() functions return value?

后端 未结 5 1980
夕颜
夕颜 2020-11-30 13:27

Anyone please tell me where the main() function of the \'C\' language returns its value?

5条回答
  •  萌比男神i
    2020-11-30 13:53

    From the C99 Standard:

    5.1.2.2.3 Program termination

    1 If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument;

    and then

    7.20.4.3 The exit function

    5 Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.

    In short, the return value of main is returned to the host environment in an implementation-defined form.

提交回复
热议问题