The C Language

a function definition

A function is a named, reusable block of work — like a recipe you can refer to by name instead of re-writing the steps every time. You hand it some inputs, it carries out its steps, and it can hand back a result. Defining a function is writing out that recipe: its name, what inputs it expects, what type of answer it returns, and the actual statements it runs.

A function definition has a return type, a name, a parenthesized list of parameters (each with its own type), and a body in braces. For example 'int add(int a, int b) { return a + b; }' returns an int, is named add, accepts two int parameters a and b, and its body returns their sum. The parameters are local variables that receive the caller's argument values when the function is called. The return statement hands a value back to the caller and ends the function; a function whose return type is void returns no value and may simply reach the closing brace or use a bare return.

Why this matters: functions are the primary way C programs are broken into manageable, testable, reusable pieces. They give a name to an idea, hide the messy details behind a clean interface, and let you call the same logic from many places without copying it. The distinction to keep straight is that a definition supplies the body and is the one place the code actually lives, whereas a prototype (a declaration) only announces the function's shape so callers elsewhere can be checked.

int add(int a, int b) { /* return type, name, parameters */ return a + b; /* hand the result back to the caller */ } /* called as: int sum = add(2, 3); sum is 5 */

A complete definition: return type int, name add, two int parameters, and a body that returns their sum.

A definition supplies the body and exists exactly once; a prototype only declares the shape. Parameters are fresh local copies of the arguments (pass-by-value), so changing a parameter inside the function does not change the caller's variable.

Also called
functionsubroutine函式副程式