What does main() return? [duplicate]

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.

Leave a Comment