Suppose that I have defined a function that takes in arguments as follow:
double aspectRatio (double length, double width) {
double ratio = length/width;
return ratio;
}
When I prototype the function before the main function, is it ok to leave out the parameter list, and leave the prototype as the following:
double aspectRatio();
Or is it a must to include the parameter list in the prototyping stage as well?
The reason that I asked this is because the program seems to run fine even without me including the parameters in the function prototype.
Also, are there any disadvantage of not including the parameters in the function prototype?
I also understood from the other posts that in C, an empty parameter ()
is different from a void parameter (void)
. That is, the following functions behave differently:
void printHelloWorld(void) {
printf("Hello World");
}
void printHelloWorld() {
printf("Hello World");
}
Would like to know what are the differences as well. Thanks!