liveBook · Manning

Function

As explained in Modern C, Third Edition

A function is a named C program unit that can be called to perform an operation and optionally produce a value.

A function is a named C program unit that performs a defined operation when called and may return a value. For example, main is defined with a body, while printf is called to produce output: <code>int main(void) { printf("..."); return 0; }</code>. section 2.1 section 2.5

Functions support C programs by:

  • Avoiding repeated code, copy-and-paste errors, and duplicated edits. section 7.0
  • Improving readability, maintainability, compilation time, and future reuse. section 7.0
  • Providing interfaces whose arguments and return types describe data flowing into and out of a computation. section 7.0
  • Delegating tasks through calls and transferring control back with returns. section 2.5

Calling and defining functions

A declaration or prototype determines how a function can be called. A definition supplies the function body. main provides the program’s entry point, and library functions such as printf and strlen provide reusable features without requiring their implementation to be repeated. section 2.1 section 7.0 section 7.4

Recursive calls

Each function call has its own copy of local variables, so a function can call itself recursively. Fibonacci examples contrast recursive, cached, and iterative forms and invite runtime measurements. section 7.4

How Modern C, Third Edition covers it

How deep it goes
Defines declarations, definitions, calls, returns, prototypes, local-variable copies, and recursion.
Examples
Uses main, printf, strlen, and Fibonacci variants as examples of entry points, library functions, recursion, caching, and iteration.
What it assumes
Assumes basic C identifiers, literals, operators, and statements while establishing main, calls, definitions, and returns.
What you can do after
Apply functions by defining reusable features, calling them through prototypes, returning values, and reasoning about recursive calls.
How it connects
Connects functions with declarations, definitions, statements, calls, returns, recursion, modularity, and interfaces.

Also explained in

Compare how 20 books explain function →

Related concepts

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