ENOTES

Differences between library and user defined functions

access_time Sep 01, 2021 remove_red_eye 26635

As we have discussed here, we have two different types of functions in C. They are library and user-defined function. Library functions are built-in functions which are defined inside C library whereas, user-defined functions are declared and defined by the programmer based on their needs.

Differences between Library and User-defined functions

Library / built-in functionsUser-defined functions
These functions are predefined in a header file or preprocessor directive.These functions are not predefined rather it is defined by user according to the requirements.
These functions can be simply used by including respective header file.These functions should be declared, defined and called in order to use.
Since, these functions are predefined programs are short.Since, these functions should be defined by the user programs are lengthy.
Program execution time is faster.Program execution time is slower.
It simplifies the program.Using more user-functions increase complexity.
Eg, strlen( ), strcmp( ), strcpy( ), strcat( )Eg, fact( ), average( ), greatest( ), anyname( )

Program example of Library functions

#include<stdio.h>
#include<string.h>
int main( )
{
char n[10],a[10];
printf(“Enter string”);
scanf(“%s”,n);
strcpy(a,n);
printf(“Copied string is %s”, a);
return 0;
}

Program example of User-defined functions

#include<stdio.h>
void sum ( ) ; //function declaration
int main ()
{
sum( ); //function calling
retun 0;
}
void sum ( ) // function definition
{
int a, b, c;
printf("Enter two number");
scanf("%d %d", &a, &b);
c=a+b;
printf("Sum is %d", c);
}

Click here for Recursive function and examples.