I've arrived embarrassingly late to this particular rodeo, but i thought i'd throw in my 2¢ anyway (I am still regularly baffled by the lack of a "cent" sign in ascii).
A function is a reusable piece of code that may take named arguments and may return a value. Note "may" doesn't mean "must", these pieces are optional. It's been laid out again, but hopefully more explanation doesn't muddy the water:
A prototype describes the return type, name, and the number and type of arguments a function takes:
int myNeatIntReturningFunction(char mySweetCharArgument, int *myExcellentIntPointerArgument, double myDubiousDoubleArgument);
In this case the return type of the function is int, its name is myNeatIntReturningFunction, and it has three arguments, a char, an int *, and a double. You do not have to name your arguments in the prototype, just say what type they are, so:
int myNeatIntReturningFunction(char, int *,double);
would work just as well.
A function implementation starts with a similar looking header, but also contains a block of code between {} that is the "function body", the code that executes when the function is called.
Code:
int myNeatIntReturningFunction(char mySweetCharArgument, int *myExcellentIntPointerArgument, double myDubiousDoubleArgument) {
int returnValue = 0;
if(myDubiousDoubleArgument > 87.32) {
returnValue += 22;
}
returnValue -=*myExcellentIntPointerArgument;
if(mySweetCharArgument >= 'A' && mySweetCharArgument <= 'Z') {
returnValue = mySweetCharArgument + ('a' - 'A');
}
if(returnValue > *myExcellentIntPointerArgument) {
*myExcellentIntPointerArgument = returnValue;
}
return returnValue;
}
Earlier you stated that printf was a "string literal". I'm not sure what you meant, but it certainly isn't that. It's first argument is often a string literal, but could also be a const char * variable. A literal is any of these:
1
5.6f
5.6
'A'
"A"
45L
12U
They are different types of literals, but literal means: exactly this value of a particular data type. This means the value of this expression is known at compile-time. The type of printf is int, so it doesn't even return a string.
When you call a function, you pass it the proper arguments, and you can assign or test its return value. There are times that a function will do something very fixed and specific, like print a banner for example, that requires no input and no return value. This is pretty rare, though, as what really makes functions interesting is they allow you to perform a task on different data and get a result. Often the result will be returned from the function, but (I can't remember if you've covered pointers yet) you can also modify variables that are passed to a function using a pointer.
Again, most of this has been mentioned, but while I'm here... The reason for prototypes is to tell the compiler in advance what a function "looks like". It's going to make assumptions if you don't give it the heads up, and it may give you warnings it should not based on these assumptions, or fail to give you warnings it should. We want to tell the compiler the most we possibly can so it can tell us the most it possibly can about potential problems. Any issue you can catch and fix at compile time is a great boon compared to having to figure it out at runtime. When we tell the compiler about our functions it can check that we're passing the right number and type of arguments, it can tell us about possibly unexpected data-conversion issues with a return type (assigning the result of a function that returns a double to an int, for example), and it's generally happier because it's well-informed.
Functions are absolutely critical to modularity. They allow us to write solid, well-tested code that we're confident performs a task correctly, and then reuse this code all over our program or throughout all of our programs. We depend on system-provided functions to get anything useful done (like your printf example). If you ever find yourself retyping or copying/pasting code from one place to another you should probably be pasting it into a function, genericizing as needed, and using the function instead.
-Lee