Functions

Summary: A function performs a specific task and can also return a value.

Functions are the building blocks of C. Every C program has at least one function, and every executable C statement appears inside some function or another. In plain English, a “function” is a group of statements that performs a specific task and often returns a value to the statement that calls it.

C functions serve the same purposes as QuickPascal procedures and functions or Basic SUB and FUNCTION procedures. They allow you to write well-organized programs that perform different tasks in separate parts.

C also uses functions to perform all input and output (I/O). Unlike other high-level languages, C has no I/O statements such as PRINT or READ. Instead, all I/O is done by calling C library functions such as printf.

Summary: Every C program has a function named main.

The VOLUME.C program contains two functions, named main and sphere (see Figure 1.1). The main execution section of every C program is itself a function named main, which marks where execution starts and ends. When you run VOLUME.C, execution starts at the beginning of the main function and stops at the end of main.