C Library Functions

C Standard library functions or simply C Library functions are inbuilt functions in C programming.

The prototype and data definitions of the functions are present in their respective header files, and must be included in your program to access them.

For example: If you want to use printf() function, the header file <stdio.h> should be included.


#include <stdio.h>
int main()
{
    // If you use printf() function without including the <stdio.h>
    // header file, this program will show an error.
    printf("Catch me if you can."); 
}


There is at least one function in any C program, i.e., the main() function (which is also a library function). This function is automatically called when your program starts.

Advantages of using C library functions

There are many library functions available in C programming to help you write a good and efficient program. But, why should you use it?

Below are the 4 most important advantages of using standary library functions.

1. They work

One of the most important reasons you should use library functions is simply because they work.

These functions have gone through multiple rigorous testing and are easy to use.

2. The functions are optimized for performance

Since, the functions are "standard library" functions, a dedicated group of developers constantly make them better.

In the process, they are able to create the most efficient code optimized for maximum performance.

3. It saves considerable development time

Since the general functions like printing to a screen, calculating the square root, and many more are already written. You shouldn't worry about creating them once again.

It saves valuable time and your code may not always be the most efficient.

4. The functions are portable

With ever changing real world needs, your application is expected to work every time, everywhere.

And, these library functions help you in that they do the same thing on every computer.

This saves time, effort and makes your program portable.

Use Of Library Function To Find Square root

Suppose, you want to find the square root of a number.

You can always write your own piece of code to find square root but, this process is time consuming and it might not be the most efficient process to find square root.

However, in C programming you can find the square root by just using sqrt() function which is defined under header file "math.h"


#include <stdio.h>
#include <math.h>
int main()
{
   float num, root;
   printf("Enter a number: );
   scanf("%f", &num);
   // Computes the square root of num and stores in root.
   root = sqrt(num);
   printf("Square root of %.2f = %.2f", num, root);
   return 0;
}


When you run the program, the output will be:


Enter a number: 12
Square root of 12.00 = 3.46

C Library Functions Under Different Header File

C Header Files
<assert.h>Program assertion functions
<ctype.h>Character type functions
<locale.h>Localization functions
<math.h>Mathematics functions
<setjmp.h>Jump functions
<signal.h>Signal handling functions
<stdarg.h>Variable arguments handling functions
<stdio.h>Standard Input/Output functions
<stdlib.h>Standard Utility functions
<string.h>String handling functions
<time.h>Date time functions