• 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

 

 

ILLUSTRATION WITH SIMPLE PROGRAM

Consider the program

Int x=4;

Main()

{

Int z;

Char* y;

y= malloc(6);

y=”Hello”;

printf(“%c”, *y);

z = square(x);

printf(“%d”, z);

free(y);

}

 

Int  square(Int k)

{

Return k*k;

}

 

 Now we see which variables in the program are stored where.

In this program we have different types of variables like x as global variable, z & k as local variable and as parameter to the function and y is dynamically allocated variable. So x is stored in fixed memory, z & k are stored in Stack Memory and the pointer y is also stored in stack memory while the 6 bytes (allocated by malloc) which are pointees of pointer y are stored in heap memory.

 

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