> this has to be before main! Why do I have to put this too! int add(int, int)
> why don't I just leave it with the prototype???
The prototype is the envelope, the function body is the letter inside the envelope. You need both if you want something to happen.
> The function definition! Why does it have to be after main???
It can be anywhere after the prototype.
Some people prefer to see main() first, then the worker functions in a top-down arrangement.
Others prefer a bottom-up style starting with the minor functions finishing with main at the end of the file.
However, when your programs no longer fit inside one source file, the whole "before or after main" doesn't mean a great deal.
> And one more thing! When I define the function, do I just call its name or its parameters too
When you prototype a function, you can omit the variable names. So these two are equivalent.
Code:
int find ( const char*, const char* );
int find ( const char*haystack, const char*needle );
Though obviously the latter provides more information about what the parameters intend to be used for.
The function definition must always name the parameters, otherwise the function body has nothing to work with.
Code:
int find ( const char*haystack, const char*needle )
{
return strstr( haystack, needle ) != 0;
}
Normally, the prototype is created from the definition by copy/paste and appending a ;
Calling the function, you can use any variable name you like, or even literal constants
Code:
char a[] = "hello", b[]="he";
find( a, b );
find( "hello", "he" );