• 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

 

 

MEMORY ALLOCATION-ILLUSTRATION-III

Now we make a function call to func1(). Hence a new frame is created in the stack and n=5 is passed as parameter. Firstly return address to the function func2() is saved on stack. Next space is allocated to variable n and given value 5. This variable n is different from the variable n in the function func2() although they have same names but different addresses. Now we have the statement int p; i.e.  again memory is allocated for another local variable p and random value is there in the memory. After this the statement p=x*n*n evaluates to store a value 2*5*5 = 50.

 

www.exploreroots.com

After this value of p is printed and value 3 gets returned. As the function func1 ends & returns to the address stored in the address register and hence its frame is de-allocated memory and memory map of stack is as:

 

www.exploreroots.com

Now we are in the function func2(). Next statement we have is k=func1(2*n); Hence a function call to func1 is made with parameter 2*5=10 and a new frame is created. In the func1 function firstly return address to func2 function is saved along with other registers. Next space is allocated to variable n and given value 10. This variable n is different from the variable n in the function func2() although they have same names but different addresses. Now we have the statement int p; i.e. again memory is allocated for another local variable p and random value is there in the memory. After this the statement p=x*n*n evaluates to store a value 2*10*10 = 200.

www.exploreroots.com

 

 

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