.TH main() "" "" "C Language"
.PC "Introduce program's main function"
.PP
A C program consists of a set of functions, one of which must be called
.BR main() .
This function is called from the runtime startup routine
after the runtime environment has been initialized.
.PP
Programs can terminate in one of two ways.
The easiest is simply to have the
.B main()
routine
.BR return() .
Control returns to the runtime startup; it closes all open file streams
and otherwise cleans up,
and then returns control to the operating system,
passing it the value returned by
.B main()
as exit status.
.PP
In some situations (errors, for example), it may be necessary to stop a
program, and you may not want to return to
.BR main() .
Here, you can use the library function
.BR exit() ;
it cleans up the debris left by the broken program
and returns control directly
to the operating system.
.PP
The system call
.B \_exit()
quickly returns control to the operating system without performing any cleanup.
This routine should be used with care, because bypassing the cleanup will
leave files open and buffers of data in memory.
.PP
Programs compiled by \*(CO return to the program that called them;
if they return from
.B main()
with a value or call
.B exit()
with a value (e.g., \fBEXIT_SUCCESS\fR or \fBEXIT_FAILURE\fR),
.B main()
returns that value to the program that invoked it (e.g., the shell).
Programs that invoke other programs through the function
.B system()
check the returned value to see if
these secondary programs terminated successfully.
If you exit from
.B main()
without explicitly returning a value (e.g., by just letting
.B main()
simply conclude, or by invoking
.B exit()
without a return status, or by invoking
.B return
without a return value),
.B main()
returns whatever random value happens to have been in the register EAX.
.SH "See Also"
.Xr "_exit()," _5Fexit
.Xr "argc," argc
.Xr "argv," argv
.Xr "C language," c language
.Xr "envp," envp
.Xr "exit()," exit
.Xr "EXIT_FAILURE," exit_fail
.Xr "EXIT_SUCCESS" exit_succ
.br
\*(AS, \(sc5.1.2.2.1
.br
\*(PX Standard, \(sc3.1.2.2
