liveBook · Manning

Function declaration

As explained in Modern C

A function declaration is a C declaration that specifies a function's name, parameter interface, and return type without necessarily defining its body.

A declaration and a definition

Consider `int main(void);` followed by `int main(void) { return 0; }`. The first line declares the function: it gives the name `main`, the return type `int`, and an interface with no parameters. The second line repeats that declaration and adds a body in braces, making it a definition. Execution starts at `main`; `return 0;` leaves the function. section 2.1 section 2.3 section 2.5

A declaration identifies a function and specifies its properties; it need not say how the function does its work. A definition supplies that missing body. TAKEAWAY: A function definition includes a declaration, but a declaration alone is not a definition. section 2.1 section 2.3

A call such as `printf(...)` delegates a task to a function. Keep the roles separate: the declaration identifies the function, the definition specifies what it does, and the call uses it. section 2.1 section 2.5

How Modern C covers it

How deep it goes
Defines the distinction through `main` and its braced body, while deferring complications in the declaration–definition relationship.
Examples
Uses `int main(void)` followed by a braced body and contrasts it with a call to `printf`.
What it assumes
Introduces identifiers and functions in context, without assuming prior knowledge of the declaration–definition distinction.
What you can do after
Evaluate/understand whether a function is merely declared or also defined by checking for its braced body.
How it connects
Connects function declarations to identifiers, function definitions, blocks, function calls, and return statements.

Also explained in

Compare how 6 books explain function declaration →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.