Yes, it works†, but it is useless.
Remember that in C, any variable that doesn't have a type specified defaults to int
, so that means that the function expands to this:
int main(int argc) {
...
}
Which is legal in C89. Most of the time, however, if you want to know the number of arguments sent to a program, you probably want the contents of those arguments, so this is mostly useless.
However, GCC (when compiled with -Wall
) gives me a warning:
Only one parameter on 'main' declaration.
It's just saying that this code is pretty much useless.
However, technically, as @hmjd noted, this is illegal, in that it is undefined behavior. However, in most implementations of C that I have came across, when you pass extra parameters to a function, they are just ignored for the most part. So, unless you are on a system where it matters if you overflow the amount of variables sent to a function, you should be fine.