Functions in C programming

In this tutorial, we will learn about user-defined function as well as standard library functions.

Functions break large computing tasks into smaller ones, and enable people to build on
what others have done instead of starting over from scratch

The function is passed a number of input parameters (or arguments) and may return a value. The function once created can be used multiple times which will helps in code reusing.

Types of functions

  1. Standard Library functions
  2. User defined functions

1. Standard Library functions


These are the built in functions in C programming that perform predefined task.  These function are defined in the header file. Once you include header file in the program you can use the standard library function.

For examples: printf()scanf() etc… are standard library functions. These function are defined in stdio.h  header file.

2. User defined functions


C program allows user to define their own function. Those function that are created by user are called user defined function.

How does function work?

Example:

#include <stdio.h>
void functionName()
{
    ... .. ...
    ... .. ...
}

int main()
{
    ... .. ...
    ... .. ...

    functionName();
    
    ... .. ...
    ... .. ...
}
functions in C programming

The execution of a C program begins from the main() function. While executing once the compiler encounter functionName program jumps to void functionName() . And start execution from there. After all codes are executed the compiler returns just below from where it was redirected.