C has two main types of functions:
1.) Library Functions:
- These are predefined functions provided by the C standard library.
- You can directly use them by including appropriate header files.
- Examples: printf(), scanf(), strlen(), sqrt(), strcpy(), etc.
Example of a Library Function:
#include <stdio.h>
#include <math.h>
int main() {
double result = sqrt(25.0); // sqrt is a library function
printf("Square root: %.2f", result);
return 0;
}2.) User-Defined Functions:
- These are custom functions written by the programmer.
- You define them to perform specific tasks that are not available as library functions.
- These functions enhance the modularity of the program.
Example of a User-Defined Function:
#include <stdio.h>
// Function declaration
int add(int a, int b);
// Main function
int main() {
int result = add(5, 7); // Function call
printf("Sum = %d", result);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}Difference Between Library Functions and User-Defined Functions:

