I don't understand how stacks and register work during a recursion or normal function calls. Where the function's parameters & statement address got copy. The book says that compiler use stacks for this purpose but registers are used for that purpose. Here is the code
main()
{
int a = 5, b = 2, c;
c = add (a, b);
printf ("sum = %d", c);
}
add(int i, int j)
{
int sum;
sum = i + j;
return sum ;
}
author says "Before transferring the execution control to the function add( ) the values of parameters a and b are pushed onto the stack. Following this the address of the statement printf( ) is pushed on the stack and the control is transferred to add( )." how return address statement works. How control returns to caller function?