• 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-II:

x= (char*)malloc(2);

With this instruction, firstly 2 bytes are allocated from the HEAP and then the starting address of the allocated memory is stored in the pointer x but the values stored in the memory allocated are random. Now note that in the pointer there is no information stored about where the allocated memory ends. So how would we know where the memory ends while accessing memory? Actually we can’t know the end. The programmer has to take care of himself otherwise it’ll cause ERROR. While storing characters a NULL character ’\0’ is stored to detect the end of memory.

www.exploreroots.com

Char* y= (char*)malloc(4);

Similar to the above case, 4 bytes are allocated for the pointer in the STACK and then the 4 bytes are allocated from HEAP and starting address is stored in the pointer.

www.exploreroots.com

 

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