Functions in C Programming

Functions in C programming language are building blocks of a C program. A function is a sequence of statements to perform a specific task and it can be called by other functions. A function may take some input and perform a logical unit of task and may return the response to calling function.
The function in C language is also known as method, subroutine or procedure.

  • A C program is a set of function calling each other.
  • We can use any number of functions in a C program.
  • All C programs must contains at least one main() function.

Advantage of Functions in C Programming

  • A large C program can divide into set of functions, where each function owns the responsibility of performing one specific task.
  • Splitting a C program into functions, makes it easy to maintain and improves understandability of very large C programs.
  • We can call a function any number of times in a program from any place which avoid rewriting same code again and again at various program.
  • We can add common utility functions in header files, So that It can be reused by other programs.

Functions in Details

Click on the links below to check detailed description of functions in C programming.

  • Function Definition in C
  • Function Declaration(prototype) in C
  • Calling a Function in C
  • Passing Arguments to a Function in C
  • Important Facts about Functions in C

How Functions work in C

  • First of all main() function of C program gets called by Operating system.
  • Execution of C program begins. Program’s statements and expressions getting executed in top to bottom sequence.
  • When control reaches a function call lets say myFunction(int val); it pauses the execution of current function and control goes inside the called function myFunction.
  • Once execution of code inside myFunction body finishes control comes back to the calling function. It resumes the execution of calling function at the next statement following the function call of myFunction.
  • At the point of any function call, control keeps on jumping between calling function and called function.
  • C program terminates when execution of main function ends.