Javatpoint Logo
Javatpoint Logo

Difference between the user-defined and the library function in C

This topic will discuss the difference between the user-defined and the library function in the C programming language. Before going to the topic, let's understand the function in the C language. A function is a self-contained group of subprograms used to perform some specific, well-defined task. The functions are divided into two parts: the user-defined and the library function.

user-defined vs library function in C

User- defined Function

As the name suggests, a user-defined function is a function written by the user to write any program code and execute specific actions. These user-defined functions can be modified and execute according to the requirement of the programmer. A programmer can change the user-defined function, but these functions are not defined in the C header files. A user-defined function is made up using the function declaration, function definition, and the function call.

Function Definition

The function definition defines the actual body of the function that perform some specific tasks in a program.


Here return type represents the function that can return any defined data type values. The return type value can be int, float, char, double, etc., where the function_name represents the name of a function that contains more than one argument in it.

Function Calling

After defining the function definition, we need to call the defined function in a program to execute its tasks. However, a function can be called multiple times by writing the function name followed by arguments lists.


Here, arg1, arg2 are the actual arguments passed to the function_name.

Function Declaration

The function declaration defines the function name, return type and the passed arguments in it. A function definition is always defined outside of the main() function in any C program.


Program to calculate the area of circle using user-defined function in C



Enter the radius of a circle: 5
The area of a circle is: 78

Program to sum two numbers using user defined function in C



Enter two numbers
The addition of two numbers is 11

Library Function

C programming language provides some library functions to perform some predefined tasks. These functions are also called the built-in or predefined function in the C header files whose meaning cannot change. When we use these functions on any program, we call the function name with appropriate header files because these functions are defined inside the header files. In other words, we did not require to write the complete code to perform a specific task; instead, we can directly call the function in our program whenever it is required. For example: printf(), scanf(), getch(), etc., are the predefined library functions.

Program to demonstrate the library function in C



Welcome to the JavaTpoint
It is a library function in the C program

In the above program, we use a printf() and getch() built-in function whose meaning or tasks are already defined in the C compiler. Therefore, we did not require to write complete code to use the printf() and getch() function in the C program.

Difference between the user-defined and the library function in C

S.No User defined Function Library function
1. A programmer creates a function according to the requirement of a program, which is called a user-defined function. A function whose prototypes are already defined in the C library is called the library function.
2. A user-defined function is required to write the complete code before using the function in a program. We don't require writing a complete code to use the library function in a program.
3. The name of any user-defined function can change easily. We can't change or modify the name of the library function because the functionality of these functions is already defined in the compiler.
4. A user defined function is not compulsory to use in any C program. We need to use the library function in every C program.
5. A user-defined function does not require writing any code inside the header files.
For example: swap() function does not require any header file.
All the library functions are predefined inside the header files.
For example: printf(), and scanf() function are defined in the stdio.h header file. And the strpcy(), strcmp() function are defined in the string.h header file.
6. A user-defined function is part of a program. Library functions are part of the C header file.
7. The programmer or user define the function at the time of writing the code. The developer in the C compiler predefines the library function.
8. Example: multiply(), sum() divide(), etc. are the user defined or user created function in a program. Example: printf(), sqrt(), strcpy(), etc.

Next TopicMemset C

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA