What is a User-Defined Function?
A user-defined function is a function created by the programmer to perform a specific task.
Definition:
User-defined functions are functions written by the programmer to perform specific operations.
Why User-Defined Functions Are Needed
- Break large programs into small parts
- Reuse code multiple times
- Improve readability
- Easy debugging
Example: User-Defined Function
c
1#include <stdio.h>
2
3// User-defined function
4void greet() {
5 printf("Welcome to C Programming");
6}
7
8int main() {
9 greet(); // Function call
10 return 0;
11}How User-Defined Function Works
- Function is defined by programmer
- Function is called from
main() - Control transfers to function
- Function executes
- Control returns to
main()
3. Key Differences (Exam Table)
| Feature | Library Function | User-Defined Function |
| Written by | C library | Programmer |
| Code visible | No | Yes |
| Modification | Not allowed | Allowed |
| Header file | Required | Not required |
| Examples | printf(), scanf() | sum(), greet() |
4. Simple Summary for Students
- Library functions are ready-made tools
- User-defined functions are custom tools you create
- Both help make programs shorter and cleaner
