English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this tutorial, you will learn about standard library functions in C language. More specifically, what they are, different library functions in C language, and how to use them in programs.
C standard library functions or simple C library functions are built-in functions in C language programming.
The prototypes and data definitions of these functions are located in their respective header files. To use these functions, we need to include the header files in the program. For example,
If you want to use the printf() function, you should include the header file <stdio.h>.
#include <stdio.h> int main() { printf("Catch me if you can."); }
If you try to use printf() without including the header file stdio.h, an error will occur.
1.Practically tested strictly
One of the most important reasons to use library functions is that these functions have been tested multiple times strictly and are easy to use.
2.Function performance optimization
Since these functions are 'standard library' functions, a group of specialized developers will continuously improve them. In this process, they can create the most efficient code optimized for the best performance.
3.Save a lot of development time
Since general functions, such as printing to the screen, calculating square roots, etc., have already been written, you do not need to create them again.
4.Function portable
With the ever-changing needs in the real world, your application is expected to run anywhere at any time. Moreover, these library functions can perform the same operation on any computer, which can be helpful to you.
Suppose you want to find the square root of a number.
To calculate the square root of a number, you can use the sqrt() library function. This function is defined in the header file math.h.
#include <stdio.h> #include <math.h> int main() { float num, root; printf("Enter a number: "); scanf("%f", &num); // Calculate the square root of num and store it in root. root = sqrt(num); printf("%.2The square root of f = %.2f", num, root); return 0; }
When running the program, the output is:
Enter a number: 12 12The square root of .00 = 3.46
C header file | |
---|---|
<assert.h> | Program assertion function |
<ctype.h> | Character type functions |
<locale.h> | The definition sets the specific regional settings, such as date format and currency symbol. |
<math.h> | Mathematical functions |
<setjmp.h> | Jump function |
<signal.h> | Signal handling function |
<stdarg.h> | Variable parameter handling function |
<stdio.h> | Standard Input/Output Functions |
<stdlib.h> | Standard Utility Functions |
<string.h> | String Handling Functions |
<time.h> | Date and Time Functions |