C Programming/C Function

Functions in C — Introduction

Updated on January 9, 2026
2 min read

What is a Function?

function is a block of code that performs a specific task and can be used again and again.

Simple definition (exam-ready):

A function is a self-contained block of code that performs a particular task.

1. Why Do We Need Functions?

Without functions, everything is written inside main(), which becomes:

  • Very long
  • Hard to read
  • Hard to debug

Functions help to:

  • Divide a program into small parts
  • Improve code readability
  • Enable reusability
  • Reduce errors

2. Real-Life Example

Think of a calculator:

  • Addition is one task
  • Subtraction is another task

Each task = function

3. Types of Functions in C

  1. Library functions

  Examples:

    • printf()
    • scanf()
    • strlen()
  1. User-defined functions

Functions written by the programmer.  we will learn later in next topic

Library Function in C

library function is a predefined function provided by C libraries.

You do not write their code — you only use them.

Definition:

Library functions are predefined functions available in header files that perform common tasks.

Why Library Functions Are Used

  • Save time
  • Already tested and optimized
  • Reduce program size
  • Easy to use

Examples of Common Library Functions

FunctionPurposeHeader File
printf()Output on screenstdio.h
scanf()Input from userstdio.h
strlen()Find string lengthstring.h
sqrt()Square rootmath.h
pow()Power calculationmath.h

Example: Library Function Program

c
1#include <stdio.h>
2
3int main() {
4    printf("Hello World");
5    return 0;
6}

Here:

  • printf() is a library function
  • Defined inside stdio.h

Important Points About Library Functions

  • Already written by C developers
  • Need correct header file
  • Faster and reliable
  • Cannot modify their internal code
Functions in C — Introduction | C Programming | Learn Syntax