During a C program, the functions that are invoked before the main function call it with the parameters from the command line. However, how is this done with a function that is declared as int main(void) without errors, as it still calls the function with parameters.
Asked
Active
Viewed 68 times
0
-
1Does this answer your question? [Why can C main function be coded with or without parameters?](https://stackoverflow.com/questions/32550081/why-can-c-main-function-be-coded-with-or-without-parameters) – walnut Dec 20 '19 at 03:53
-
I had read that post and still didn't get how it worked. – ainam2005 Dec 20 '19 at 03:55
-
Internally, functions ignore extra arguments that they aren't expecting. – Barmar Dec 20 '19 at 03:56
-
Does this only apply the main method, as when testing this, a compilation error for too many parameters occurred. – ainam2005 Dec 20 '19 at 03:57
-
I assume you're thinking in terms of `stdcall`? With `cdecl` it isn't important what kind of arguments are passed. – o11c Dec 20 '19 at 03:57
-
I was thinking in the terms stdcall – ainam2005 Dec 20 '19 at 03:58
-
Are you asking for taking input from the command line i.e command-line arguments?? – Strange Dec 20 '19 at 05:34
-
@ainam2005 It applies to any function, but the compiler won't let you compile a call if it doesn't match the function declaration. The reason you can do it with `main()` is because you don't write the call anywhere in your program, it's called automatically by the run-time library, which is already compiled. – Barmar Dec 20 '19 at 05:54
-
If you want to see it happen with a user-defined function, put the function definition and call in two different `.c` files. Define the function with no arguments, but declare it with 2 arguments in the calliing file. – Barmar Dec 20 '19 at 05:57