Saturday 31 January 2015

C Standard Library Functions

C Programming

C Standard Library Functions

C Standard library functions or simply C Library functions are inbuilt functions in C programming. Function prototype and data definitions of these functions are written in their respective header file. For example: If you want to use printf() function, the header file <stdio.h> should be included.
#include <stdio.h>
int main()
    {

/* If you write printf() statement without including  header file, this program will show 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 program is called at program starts.
There are many library functions available in C programming to help the programmer to write a good efficient program.
Suppose, you want to find the square root of a number. You can write your own piece of code to find square root but, this process is time consuming and the code you have written may not be the most efficient process to find square root. But, in C programming you can find the square root by just using sqrt() function which is defined under header file "math.h"

Use Of Library Function To Find Square root

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

List of Standard Library Functions Under Different Header Files in C Programming

C Header Files
<ctype.h>
<math.h>
<stdio.h>
<stdlib.h>
<string.h>
<time.h>

No comments:

Post a Comment