Difference between the user-defined and the library function in CThis 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 FunctionAs 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 DefinitionThe function definition defines the actual body of the function that perform some specific tasks in a program. Syntax: 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 CallingAfter 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. Syntax: Here, arg1, arg2 are the actual arguments passed to the function_name. Function DeclarationThe 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. Syntax: Program to calculate the area of circle using user-defined function in CArea.c Output: Enter the radius of a circle: 5 The area of a circle is: 78 Program to sum two numbers using user defined function in CAdd.c Output: Enter two numbers 5 6 The addition of two numbers is 11 Library FunctionC 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 CBuilt.c Output: 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
Next TopicMemset C |