Why do function prototypes include parameter names when they're not required?

No, these are not necessary, and are mostly ignored by the compiler. You can even give them different names in different declarations; the following is entirely legal:

int foo(int bar);
int foo(int biz);
int foo(int qux) {
    ...
}

(The compiler does check that each name is used only once in the same argument list: int foo(int bar, int bar); is rejected.)

The reason to put them in is documentation:

  • If someone reads your header file, they can tell at a glance what each parameter is used for.
  • If you use a fancy IDE, it can show you the parameter names when you begin typing the function call.
  • Documentation tools like Doxygen can parse the parameter names and show them in the documentation.

Parameter names are completely optional, and have no effect on compilation. They may be placed there for better readability of code.


You don't need parameter names in declarations. They are purely documentation.

You don't even need names in definitions:

int f(int)
{
    return 0;
}

compiles just fine in C++ (though not in C). This is sometimes useful for e.g. inheritance, overloading, function pointers.