Library Function in C

Library Function in C

Instructor: Martin Gibbs

Martin has 20 years experience in Information Systems and Information Technology, has a PhD in Information Technology Management, and a master's degree in Information Systems Management. He is an adjunct professor of computer science and computer programming.

Cite this lesson

C programming is a language used in computing to serve general purposes. Learn about standard library functions in C programming and review standard input and output, as well as math functions, to gain understanding. Updated: 01/24/2022

Standard Libraries

Imagine that you want to display output to the screen, but each time you want to display output you have to re-write 1500 lines of special code to make that happen. This is very inefficient and wasteful - not to mention the 1500 opportunities for bugs in your program!

Thankfully, the C programming language comes with a huge library of functions that you can use in your code, without having to re-write everything. You only need to include the library at the top of your code. When you use a command such as printf (to print to the screen), you're actually using a function that is in a standard C library.

Libraries are included in your code by referencing the header file. Think of it as the link to the library. To add the header file to your code, add the following at the top of your program (before any other statements):

  1. #include <filename.h>

Note that there's no semicolon at the end of this line. One of the most common libraries used is the stdio library, which includes functions to write output to the screen and collect input from the user:

  1. #include <stdio.h>
  2. int main(void) {
  3. /* Rest of program */
  4. }

Now, let's take a look at some of the libraries, starting with stdio.h.





Video Thumbnail





 Speed Normal


Stdio.h: Standard Input/Output

First, here's an example of some stdio.h code:

  1. #include <stdio.h>