Possible Duplicate:
What should main() return in C/C++?
What value does this function return. just plain main.
main()
{
...
}
and if a function has two mains , what happens?
Possible Duplicate:
What should main() return in C/C++?
What value does this function return. just plain main.
main()
{
...
}
and if a function has two mains , what happens?
What value does this function return.
main
needs to be declared as returning an int
. The return value is passed to the caller, which is usually the operating system.
5.1.2.2.1 Program startup
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[]) { /* ... */ }
and if a function has two mains , what happens?
Linker reports an error.
Assuming you're using a C89 or earlier compiler, then
main()
{
...
}
returns int
. If you're using a C99 or later compiler, it's an error.
As of C99, if you reach the ending }
of main
without an explicit return, the return value is 0. Not sure about C89 or earlier.
Not sure what "a function has two mains" is supposed to mean. If a program has two main
functions defined, then you'll most likely get a duplicate definition error at link time.