What are functions in C?

A function is a self-contained block of statements that perform a particular task.

Types

  1. Standard Function

  2. User Defined Function

Standard function

These are pre-defined functions that are already present in the compiler and cannot be edited.

Examples: printf and scanf

User-defined functions

These functions are defined by the user.

Advantages of functions:

  1. Reduces the length of the program
  2. Easy to debug the program
  3. Uses a top-down modular programming approach
  4. Functions can be used by many other programs

User-defined functions can be of four types

  1. Functions without parameters or return values
  2. Functions with parameters and without return values
  3. Functions without parameters and with return values.
  4. Functions with parameters and return values.
#include<stdio.h>
// Function
int DoubleTheNumber ( int number ){
int temp = number + number;
return temp;
}
int main() {
// calling function
int val = DoubleTheNumber(10);
printf("The number is : %d\n", val);
return 0;
}