---
title: "Advantages of using functions"
subject: "Computer Programming"
chapter: 6
key: "semester_1/computer_programming:advantages-of-functions"
source: https://www.bctengineer.com/q/semester_1/computer_programming/advantages-of-functions
site: BCT Engineering
---

# Advantages of using functions

Computer Programming · Chapter 6: User-Defined Functions

- Asked in: 2073 Shrawan, 5 marks
- Video: [Introduction to Functions in C](https://www.youtube.com/watch?v=3lqgdqoY83o) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/advantages-of-functions
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-6

## Question

What are the advantages of using functions? Differentiate between Library functions and User-defined functions with suitable example.

## Short answer

Functions promote modularity, reusability, and easier debugging. Library functions (e.g., printf, sqrt) are pre-written in headers and cannot be modified; user-defined functions (e.g., cube, area) are written by the programmer, can be modified, and are defined in the program itself.

## Answer

#### Advantages of functions
- **Modularity:** a big program is divided into small parts, each easy to write and test.
- **Reusability:** write once, call many times (even from other programs).
- **Less code:** repeated code is not rewritten, so programs become shorter.
- **Easy debugging and maintenance:** an error is found and corrected in one place.
- **Team work:** different programmers can develop different functions.
- **Readability:** `main()` reads as a list of meaningful steps.

#### Library functions versus user-defined functions

| Library function | User-defined function |
|---|---|
| Already written and stored in the C library | Written by the programmer |
| Header file must be included | Defined/declared in the program itself |
| Cannot be modified | Can be modified as required |
| Examples: `printf()`, `sqrt()`, `strlen()` | Examples: `cube()`, `area()` |

```c
#include <stdio.h>
#include <math.h>
double cube(double x)          /* user-defined function */
{
    return x * x * x;
}
int main(void)
{
    printf("sqrt(25) = %.1f\n", sqrt(25.0));   /* library function */
    printf("cube(3)  = %.1f\n", cube(3.0));
    return 0;
}
```
Output:
```text
sqrt(25) = 5.0
cube(3)  = 27.0
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Reusability means?
   A. Copy code
   B. Global
   C. No tests
   D. Write once, call many times
   Answer: D. Reuse. (Key point: Reusability)

2. Library functions?
   A. Already written, need header
   B. Written by programmer
   C. Modifiable
   D. No header
   Answer: A. printf etc. (Key point: Library)

3. User-defined?
   A. Stored in library
   B. Written by programmer, modifiable
   C. No call
   D. Not modifiable
   Answer: B. cube(). (Key point: User-defined)

4. Debugging benefit?
   A. None
   B. Slower
   C. Error fixed in one place
   D. More code
   Answer: C. Modular. (Key point: Debugging)

## Related in Computer Programming

- [Significance of user defined functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asignificance-user-defined-functions) — Computer Programming, chapter 6
- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
- [FORTRAN constants, variables, library functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-constants-variables-library) — Computer Programming, chapter 11
- [Merits of functions; actual vs formal parameters](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Audf-merits-demerits-parameters) — Computer Programming, chapter 6

## Related in other subjects

- [Convert user-defined type to basic type](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Auser-to-basic-conversion) — Object Oriented Programming, chapter 5
- [User-level versus kernel-level threads](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Auser-vs-kernel-threads) — Embedded System, chapter 6, asked 2×
