How is the function declaration different from the function prototype?
I'm posting this question in reference to this answer on a question.
A Function declaration may/may not not include the function arguments.
While a Function Prototype must include the function arguments.
From Wikipedia:
Consider the following function prototype:
int fac(int n);
This prototype specifies that in this program, there is a function named fac
which takes a single integer argument n
and returns an integer. Elsewhere in the program a function definition must be provided if one wishes to use this function.
It's important to be aware that a declaration of a function does not need to include a prototype. The following is a prototype-less function declaration, which just declares the function name and its return type, but doesn't tell what parameter types the definition expects.
int fac();
A prototype is a declaration, but a declaration not always is a prototype. If you don't specify the parameters, then that's only a declaration and not a prototype. That means the compiler won't reject a call to that function complaining it wasn't declared, but won't be able to check if the parameters passed are correct (as it would if you had a prototype).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With