Ch 8 · Functions · C

Topic 8 of 13 in C — Complete Tutorial (Beginner) — 2 lessons.

What is a Function?

A function is a named, reusable block of code that performs a task. Instead of repeating code, you write it once in a function and call it whenever needed (the DRY principle). A C function states its return type (the kind of value it gives back, or void for nothing), a name, and parameters in brackets. You use the return keyword to send a value back to wherever the function was called.

Function Prototypes

In C, a function must be known to the compiler before it is used. If you want to define a function *below* main (where many people prefer it for readability), you first declare a prototype at the top — just the function's signature ending in a semicolon. The prototype promises "this function exists; here is its shape," and the full definition comes later. This is a small but important habit in C.

All topics in C Beginner

  1. Introduction to Programming & C
  2. Your First C Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Arrays
  10. Strings
  11. Pointers
  12. Structures
  13. Mini-Projects & Practice