What are functions in C?
A function is a self-contained block of statements that perform a particular task.
Types
-
Standard Function
-
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:
- Reduces the length of the program
- Easy to debug the program
- Uses a top-down modular programming approach
- Functions can be used by many other programs
User-defined functions can be of four types
- Functions without parameters or return values
- Functions with parameters and without return values
- Functions without parameters and with return values.
- Functions with parameters and return values.
#include<stdio.h>// Functionint DoubleTheNumber ( int number ){int temp = number + number;return temp;}int main() {// calling functionint val = DoubleTheNumber(10);printf("The number is : %d\n", val);return 0;}