Creating Functions That Take Arguments

The next logical evolution of your user-defined functions is to have them take arguments. Most C functions take arguments, like isalpha(), which expects a character to be passed to it. To have your functions take arguments, you need to define them—both in the prototype and in the formal definition—with the type of arguments expected:

void my_func (int age, int year);
int main (void) {
   // Call my_func().
}
void my_func (int age, int year) { ...

When calling a function that takes arguments, you need to then pass it the appropriate values. As you've already seen, there are many ways of doing this, from passing literal values to variable values to the results of calculations. Each of these function calls are ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.