Some example i run into for a program that deals with menu..
He declared all the function before the main function as i understand should be, and then one of the function that is a void function was also mentioned inside the main:
char get_choice(void);
char get_first(void);
int get_int(void);
void count(void);
int main(void)
{
int choice;
void count(void);
while ( (choice = get_choice()) != 'q')
{
switch (choice)
{
case 'a' : printf("Buy low, sell high.\n");
break;
case 'b' : putchar('\a'); /* ANSI */
break;
case 'c' : count();
break;
default : printf("Program error!\n");
break;
}
}
printf("Bye.\n");
...(functions implementations)
Can you please tell me why is that? tnx
No reason at all, this is just a pointless repetition of the prototype.
These are just declaration of the functions not definitions.Not too sure why count function is declared twice though.The declaration is just saying to the compiler that there is something there with this name.Perhaps the programmer forgot to define the method?
A declaration provides basic attributes of a symbol: its type and its name. A definition provides all of the details of that symbol--if it's a function, what it does; if it's a class, what fields and methods it has; if it's a variable, where that variable is stored.
eg declaration looks like this:
void count(void);
eg definition looks like this:
void count(void){
......
}
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