Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Wednesday, November 11, 2020

Library Function in C

welcome2protec-Library function in C language are built-in function which are grouped together and placed in a common place called library function.

Library function | welcome2protec

Library function in C language are built-in function which are grouped together and placed in a common place called library function. Each library function in C performs specific operation. In order to use these library functions you need to import appropriate header files at the beginning of a program. Library function is also known as predefined function.

Note: All the library functions are declared in header files and its definition is stored in library file. Therefore, In order to use these library functions you need to include appropriate header files before writing the any program.



For Example:

If you want to use printf() and scanf() functions, the header file #include <stdio.h>  should be include in our program.

 #include <stdio.h> 
 int main()
 {
     int a,b;
     printf("Enter two numbers:");
     scanf("%d,%d", &a, &b);
     prinf("You have entered numbers %d and %d", a, b);
 }
 

Output

 Enter two numbers: 10 20
 You have entered numbers 10 and 20
    

Note: If you try to use printf() and scanf() functions without including the header file #include <stdio.h> you will get an error.


Advantage of using C library functions:

  • Simple and easy to use: These functions has gone through multiple rigorous testing and are easy to work.
  • The functions are optimized for performance: Since these functions are standard library functions, a dedicated group of developers constantly work on it and make them better. In the process, the are able to create the most efficient code optimized for maximum performance.
  • 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. whenever you need these function you can call and use them in your program.
  • The functions are portable: Whenever changing real-world needs, your application is expected to work every time, everywhere. And, these library function help you in that they do the same thing on every computer.

Example: Square root using sqrt() function

Suppose, you want to find the square root of a number, so you can use the sqrt() library function to compute the square root of a number. To use this function you need to include <math.h> header file at the beginning of a program. Since sqrt() function is declared in #include <math.h>  header file.

 
 #include <stdio.h> //declaration of printf() and scanf() 
 #include <conio.h> //declaration of getch()
 #include <math.h>  //declaration of sqrt()
 void main()
 {
     float num, root;
     clrscr();
     printf("Enter a umber: ");
     scanf("%f", &num);
   
     /* Calculate the square root  of given number and stores in root */
     root = sqrt(num);    
     printf("square root of %.2f = %.2f", num, root);
     getch();
 }
  

Output

 Enter a number: 12
 square root of 12.00 = 3.46
  

Note: As you can see, clrscr(), printf(), scanf(), sqrt(), and getch() these all are the example of library functions which are used in the program by calling it directly.


Library Functions in Different Header Files:

A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. You need to include appropriate header file at the beginning of a program to supply the declarations you need to invoke

List of header file in C language.

Header file Description
<assert.h> Program assertion functions
<conio.h> console Input/output 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










Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us