How function calls work in C

How function calls work in C programming language.

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.

From which function execution of any C program starts.

Execution of any C program starts from main() function.

What are the various ways of passing arguments to a function in C.

We can pass arguments to a function in C in two ways:

  • Call by value : Any change in the formal parameters of the function have no effect on the value of actual argument. Call by value is the default method of passing parameters in C.
  • Call by reference : The address of the variable is passed to the formal arguments of a function. Any change in the formal parameters of the function will effect the value of actual argument.