Click for Table of Contents
The C Primer
Book and Reference Collection
Copyright © 2024 by Rance D. Necaise
Table Of Contents
The C Primer
Copyright © 2024
Rance D. Necaise

2.3 The Standard Library

C has no built-in functions as part of the language itself, but it does have a large standard library. A library is a collection of code that has been written and compiled by someone else, ready for use in a C program. A standard library is a library that is considered part of the language and must be included with the compiler for that language. The C standard library provides a large collection of type definitions, functions, and constant variables for solving a wide range of problems from basic tasks such as string processing, and mathematical computations to the more advanced like memory management and the utilization of operating system services.

Include Directive

The C standard library is organized into modules. Related functions and data types are grouped together in the same module. To utilize the resources provided by a module, the module must be explicitly included in your program before they can be used. The math.h module from the standard library includes a number of mathematical functions and related constant variables. To use any function from this module, you must first include the module. This is done using the #include compiler directive

#include <math.h>

Modules must be included at the top of your source program, which is typically done immediately following the file comment. Here, the stdio.h module is included in order to utilize the printf function for displaying text to the terminal

/* hello.cc
   A sample C program.
*/


#include <stdio.h>

int main()
{
  printf("Hello World!\n");

}

Modules in C are comprised of two files: a header file and a source or implementation file. The two files have the same name, but different extensions. The header file is identified by the extension .h. When a module is included within a program, it is the header file that has to be included. You will learn more about modules and how to write your own user-defined modules in a later chapter.

Standard Library Modules

The C standard library is officially comprised of 29 modules. Additional standard modules for accessing and working system services are defined by the various operating systems. While a large number of modules are available, most C programs use only a small subset of those. The more commonly used modules are shown in Table 1.

Header FileDescription
ctype.h character handling functions.
errno.h error codes reported by some C functions.
math.h C mathematical functions.
stdio.h C standard and file input/output routines.
stdlib.h C standard general utility functions.
string.h C-style string functions.
Table 1: Commonly used C standard library modules.
Page last modified on February 10, 2024, at 01:55 PM