return 0;
for you. However, this is a special case -- in other words, a weird syntax deviation from all other functions, so I always just put it in just to be explicit.
|
|
|
|
In both C and C++, main() must return int. That is the standard. |
The ISO C++ Standard (ISO/IEC 14882:1998) specifically requires main to return int. But the ISO C Standard (ISO/IEC 9899:1999) actually does not. This comes as a surprise to many people. But despite what many documents say, including the Usenet comp.lang.c FAQ document (at great length), the actual text of the C Standard allows for main returning other types. |
The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /* ... */ } or equivalent9); or in some other implementation-defined manner. 9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on. |
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; reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environment is unspecified. |
int main(...)
.