Unit III - Function call
Unit III - Function call
Overview
• Function call stack in C is a dynamic data structure where elements
are stored at contiguous memory locations. Function call stack is
maintained for every function call where it contains its own local
variables and parameters of the callee function.
• In fact, the function call stack also stores the return address of the
function itself. Function call stack in c is widely used in many
applications like recursion and calling functions.
What are Stacks in C?
• In C, stack is a Linear Data Structure where elements are
stored at contiguous memory locations.
• Stack follows the LIFO mechanism, i.e. Last in First Out. Let’s
understand LIFO mechanism more clearly by an example.
• In tower of Hanoi, all the disks are placed on a peg. It must be placed
on the top of the peg to insert a new disk.
• The top disk must be removed from the peg before removing any other
disk, this is the LIFO mechanism.
What is Call Stack ?
• Call stack is a dynamic data structure
maintained inside the RAM memory by the
Operating System.
• Primary task of Function Call Stack in C is to #include<stdio.h>
manage the function calls and how they pass
void f2() {
parameters to each other. return;
• A call stack is maintained for each task and }