why main can't be void

why return type of main can't be main
well main can have return type as void but some compilers like "codeblocks" dont allow it
I don't really understand your question, but here's a hint:

Main can be void, but if it is void, then it will not have a return operation. Every other definition type of a function (int, bool, double, etc...) will have a return value, but void will not. If I'm not mistaken, it is called a subroutine, because it doesn't has a return operation to the exterior, like a function has. If I'm mistaken too, please someone correct me too... Anyways, I always use main below void classification, but he is right; some compilers are troublemakers with this kind of stuff
Last edited on
It's just a statement of fact. The signature should be int main(int, char**).

You can get away with not declaring the arguments for C compatibility, but the return code is not optional. It is passed back to the calling program and can be use to control script files.
i found a statement in wikianswers that says

"A function returns a value whereas a subroutine does not. A function should not change the values of actual arguments whereas a subroutine could change them. "

what if i pass the arguments in the function by reference then they can be changed. Doesnt this contradict the above statement


main can be void or other than int but that isn't the standard, the standard says :
It [main] shall have a return type of type int, but otherwise its type is implementation-defined
Last edited on
So after all this, the answer is, to paraphrase Bazzy, "because the standard says so".

The return value from main() is the exit code passed from the program back to the shell that launched it. Many, many tools rely on these return values. make, for example, being one of them. Make only knows if a file failed to compile by virtue of the exit code of the compiler process back to the shell.

Topic archived. No new replies allowed.