Is main with parameter list of void different from main with an empty parameter list?
c, program-entry-point, void
Solution
In C, in general, `(void)` means no arguments required in function call, while `()` means unspecified number of arguments.
e.g.
void foo(void)
{
// body
}
void bar()
{
//body
}
In calling enviroment,
foo(); // Correct
foo(1); // Incorrect
bar(); // Correct
bar(1); // Also correct
This was the general explanation.
But for your case for main() , C99 Standard says that,
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[]) { /* ... */ }` or equivalent;
or
in some other implementation-defined manner.
So, in this `void main(void)` return type should be `int`.
And at last , for `main()`, return type is not given so implicitly return type would be `int`.
Problem
Possible Duplicate: Why is the type of the main function in C and c++ left to the user to define? What is a void ? Anyone provide some examples, proper use of void ? And what is the difference when we write `void main (void)` or `main()` ?
Related problems
- What should main() return in C and C++?
- Why does a main function without a return statement return value 12?
- Difference between main(void) and main() in C
- Why is the type of the main function in C and c++ left to the user to define?
- Why is the type of the main function in C and c++ left to the user to define?