C Tutorial

C Tutorial C Language Environment Setup Execution flow of C program C printf and Scanf C Data type C Token Variable in C Operators in C Comments in C Escape Sequence in C C – Storage Classes C Decision control statement Loop Statement in C Break, continue and goto statement in C Type Casting in C Function in C Recursion in C String in C C Array Pointer in C Dynamic memory allocation C –Structure Nested Structure in C Union in C File Handling in C C pre-processor Static Function In C Sizeof In C Selection Sort In C Scope Of Variables In C Runtime Vs Compile Time In C Random Access Lseek In C Queue Implementation In C Pseudo Code In C Prototype In C Pointer To Pointer In C Pointer Arithmetic In C Passing Array To Function In C Null Character In C Merge Sort In C Macros In C Library Functions In C Memory Leak In C Int In C Goto And Labels In C Fibonacci Series In C Fflush In C Derived Data Types In C Data Types In C Const Vs Volatile In C Character Set In C Character Class Tests In C Calloc In C C Pointers Arrays In C Include In C Clrscr In C C Vs Java String Literals In C Types Of Pointers In C Variables In C Volatile In C Why C Is A Middle Level Language Infix To Postfix Program In C Ceil function in C LCM of two numbers in C Quick sort in C Static in C function pointer as argument in C Top Array Keywords in C Add two numbers using the function in C Armstrong program in C using function Array, Declaring Arrays and Array Initialization Limitations of Inline Function in C Merge and Merge sort with example in C Do-While Loop in C For Loop in C While-Loop in C Difference between while and do-while loop in C Array Of Structures in C Data Structures And Algorithms in C Types Of Structures In C How to Avoid Structure Padding in C Use of Structure in C Do WHILE LOOP in C Programming Examples For Loop in C Programming Examples Entry Control Loop in C Exit control loop in C Infinite loop in C Nested loop in C pow() function in C String Handling functions in C

Library Functions in C

What are library functions?

Library functions are the built-in functions (functions provided by the system) which are stored in the library. The library is the common location where these functions are grouped together and placed.

Each function in the library performs a specific task(operation) and to make things easy for the programmer.

The library functions are prototyped and defined at the time of designing the compiler and are present in their respective header files.

Eg: The main() function, printf() function etc. are some of the commonly used functions that are the library functions in C.

* The header files are implemented in the C program using the following command,


For eg: #include<stdio.h>, #include<conio.h> …

* If we do not use the header files, the program will throw an error.

For eg: In order to use the printf() function, <stdio.h> should be included in order to print the desired output.

Significance/ Advantages of library function

The major reason to use library functions is that they make the work of a programmer easy, the programmer can simply use the pre-existing codes available in the compiler and need not worry about declaring and defining his own code in order to perform certain basic functions.

The other advantages of using library functions are as follows:

  • Flexibility
  • Performance optimized
  • Time-saving
  • Portability and reliability

Header File Functions

Most of us are aware of various header files or library functions as they are often used while programming in C. Following is a list of commonly used library functions and the library files in which they are included:

Header FileMeaningLibrary Functions
<stdio.h>Standard input-output headerprintf(),scanf(),getchar(c), putchar(s) etc.
<conio.h>Console input-output headerclrscr() , getch() etc.
<stdlib.h>Standard library headercalloc() and malloc()
<math.h>Math header (carry out mathematical calculations)sqrt(d),pow(d1,d2) etc.
<string.h>String header (performs operations on strings)strcpy,strlen,strrev etc.
<ctype.h>Character type header (carry out operations on character)isdigit(), tolower() , toupper() etc.

Accessing Library Function

A library function can be accessed by following the simple steps;

  1. Writing the function name
  2. Writing the list of arguments
  • The arguments must be enclosed in brackets. They must be separated by commas.
  • There may be no arguments (in some cases)

Eg: pow (p1,p2) → arguments enclosed in brackets and separated by commas


    Function name

Program 1: use of <stdio.h> header files and use of printf()  and scanf() library functions

#include<stdio.h>    // Use of stdio.h header

#include<stdio.h>    // Use of stdio.h header

int main()

char name[30];

printf ("Enter your name here : "); // Use of printf() library function
scanf ("%s", name); // Use of scanf() library function

printf("The name entered was: %s\n", name);

return 0;


Output of the program:

Library Functions in C

Program 2: use of <math.h> header file and use of sqrt() library functions

#include <stdio.h>
#include <math.h>

int main()
   float num, sq_root;
   printf("Enter a number: ");
   scanf("%f", &num);

   sq_root = sqrt(num);  // computes the square root of num and stores in root.

   printf("Square root of %.2f = %.2f", num, sq_root);
   return 0;


Output of the program:

Library Functions in C