• Home
  • Tutorials
  • Interviews
  • Info Seed
  • Forums
  • Projects
  • Links
  • Contact Us
C Language
C POINTERS
MEMORY MANAGEMENT
INTRODUCTION
FIXED MEMORY
STACK MEMORY
HEAP MEMORY
Illustration with simple program
Functions to manage HEAP MEMORY
MEMORY ALLOCATION
MEMORY ALLOCATION-II
MEMORY ALLOCATION-III
MEMORY ALLOCATION-IV
Illustrations of MEMORY ALLOCATION
Illustration I
Illustration-I Contd..
Illustration-I Contd..
Illustration-I Contd..
Illustration II
Illustration-II Contd..
Illustration-II Contd..
Illustration III
Illustration IV
FRAME POINTER

 

 

NEXT ILLUSTRATION-II:

And then function call is made to function fun() and a new frame is created in the stack. Firstly return address to main is saved in the stack. Next memory is allocated for variable n and 2 is stored in n.

www.exploreroots.com

Now n—is executed and n becomes 1. Then if statement is executed and another call to fun() is made and value 1 is passed. Again return address to function Fun() is saved and then value 1 is stored in variable n. execution of n- - decreases the value to 0.

www.exploreroots.com

Q-Why do sometimes we encounter an error named as ‘Stack Overflow ERROR’?

Ans: It occurs due to the infinite recursion calling. As we can see in the above case that in case of recursion (when a function calls itself), everyt ime a function is called new memory is allocated in the stack and hence in case of infinite incursion, a function is called infinite times and hence memory is allocated infinite times and hence we fall in shortage of memory in stack which is STACK OVERFLOW.

  

 

previous next
| Copyright © 2009 exploreroots- All Rights Reserved | Disclaimer |