Difference between user defined function and library function in C/C++ Last Updated : 27 Jun, 2023 Comments Improve Suggest changes Like Article Like Report Library Functions These functions are the built-in functions i.e., they are predefined in the library of the C. These are used to perform the most common operations like calculations, updation, etc. Some of the library functions are printf, scanf, sqrt, etc. To use these functions in the program the user has to use a header file associated with the corresponding function in the program. Example If the user has to use print the data or scan the data using an input stream then we have to use functions printf() and scanf() in C program and cin and cout in C++ program. To use these functions the user has to include #include<stdio.h> preprocessor directive in C program and #include<iostream> preprocessor directive in C++ program. C // C program to illustrate inbuilt function // Header file for printf function #include <stdio.h> // Driver Code int main() { // Library function printf printf("GeeksforGeeks!"); return 0; } C++ // C++ program to illustrate inbuilt function #include <iostream> using namespace std; // Driver Code int main() { // Library function printf cout << "GeeksforGeeks!"; return 0; } OutputGeeksforGeeks!User-defined Functions These functions are designed by the user when they are writing any program because for every task we do not have a library of functions where their definitions are predefined. To perform according to the requirement of the user, the user has to develop some functions by itself, these functions are called user-defined functions. For such functions, the users can write their own logic according to the requirement. Example If we want to perform the addition of two numbers then below is the program to illustrate the addition of two numbers using a user-defined function. C // C program to illustrate user-defined function #include <stdio.h> // User-defined function to find the sum of a and b void findSum(int a, int b) { // Print the sum printf("Sum is: %d", a + b); } // Driver Code int main() { // Given two numbers int a = 3, b = 5; // Function Call findSum(a, b); return 0; } C++ // C++ program to illustrate user-defined function #include <iostream> using namespace std; // User-defined function to find the sum of a and b void findSum(int a, int b) { // Print the sum cout << "Sum is: " << a + b; } // Driver Code int main() { // Given two numbers int a = 3, b = 5; // Function Call findSum(a, b); return 0; } OutputSum is: 8Difference between User-Defined Function and Library Function Tabular Representation to illustrate the difference between the user-defined function and the library function in C/C++: S.No.User-Defined Functions Library Functions 1 These functions are not predefined in the Compiler. These functions are predefined in the compiler of C language.2 These functions are created by users as per their own requirements.These functions are not created by users as their own.3 User-defined functions are not stored in library files.Library Functions are stored in a special library file.4 There is no such kind of requirement to add a particular library.If the user wants to use a particular library function then the user has to add the particular library of that function in the header file of the program.5 Execution of the program begins from the user-define function.Execution of the program does not begin from the library function.6 Example: sum(), fact(),...etc.Example: printf(), scanf(), sqrt(),...etc. Comment More infoAdvertise with us Next Article Difference between user defined function and library function in C/C++ itskawal2000 Follow Improve Article Tags : C++ CPP-Basics CPP-Functions Practice Tags : CPP Similar Reads Difference between virtual function and inline function in C++ Virtual function: Virtual function is a member function which is declared within a base class and is redefined by a derived class. Inline function: Inline function is a normal function which is defined by the keyword inline, it is a short function which is expanded by the compiler and its arguments 2 min read C++ - Difference Between Functors and Functions In C++, we have multiple options to operate over the data like in the case where we can use functions and functors. Although both seem to be similar in a few ways but have multiple differences between them. Let's check the differences between functions and functors in C++. What are functions? Functi 3 min read Difference between Virtual function and Pure virtual function in C++ Virtual Function in C++ A virtual function is a member function which is declared within a base class and is re-defined(Overridden) by a derived class. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execu 2 min read Difference Between Inline and Normal Function in C++ Inline Function is a function that is expanded inline by the compiler when it is invoked. During function call, a lot of overhead tasks are performed like saving registers, pushing arguments to the stack, and returning to the calling function. These overheads are time-consuming and inefficient for s 4 min read Difference between Static and Friend Function in C++ Static Function: It is basically a member function that can be called even when the object of the class is not initialized. These functions are associated with any object and are used to maintain a single copy of the class member function across different objects of the class. This function is denot 3 min read Difference between declaration of user defined function inside main() and outside of main() The declaration of a user-defined function inside the main() function and outside main() is similar to the declaration of local and global variables, i.e. When we declare a function inside the main, it is in local scope to main() and that function can be used in main() and any function outside main( 4 min read Difference between "int main()" and "int main(void)" in C/C++? Note: This was true for older versions of C but has been changed in C11 (and newer versions). In newer versions, foo() is same as foo(void). Consider the following two definitions of main(). Definition 1: C int main() { /* */ return 0; } C++ int main() { /* */ return 0; } Definition 2: C int main(vo 3 min read Difference Between STL and Standard Library in C++ In C++, the term "Standard Library" and "Standard Template Library" are often misinterpreted as the same. Although they sound same with only a single word difference, they refer to the different part of the C++ programming language. In this article, we will learn what's the difference between the C+ 3 min read Difference between Inline and Macro in C++ 1. Inline : An inline function is a normal function that is defined by the inline keyword. An inline function is a short function that is expanded by the compiler. And its arguments are evaluated only once. An inline functions are the short length functions that are automatically made the inline fun 3 min read Difference between int* p() and int (*p)()? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, a pointer must be declare before storing any variable address. The general form of a pointer variable declaration is: Syntax: type *var_name; Here, type 2 min read Like