Tuesday, February 15, 2011

Data segment......

A data segment is one of the sections of a program in an object file or in memory, which contains the global variables and static variables that are initialized by the programmer. It has a fixed size, since all of the data in this section is set by the programmer before the program is loaded. ...

Data segment is divided in to four parts.......

1.Data Area
All static and extern variables are stored in data area,it is permanent memory space and variable will store in memory until and unless program ends....

2.Code Area
Function pointer can only access code area. Size of this area is always fixed and it is read only memory area.

3.Heap Area
This memory area is use to allocate memory dynamically. In c we can allocate the memory space dynamically by using function malloc and calloc. It always allocates memory in the heap area. Its size is variable and depends upon free space in the memory

4.Stack Area

All automatic variables and constants are stored into stack area. Automatic variables and constants in c:

1.       All the local variables of default storage class.
2.       Variables of storage calls auto.
3.       Integer constants, character constants, string constants, float constants etc in any expression.
4.       Function parameters and function return value.

Variables in the stack area are always deleted when program control reaches it out of scope. Due to this stack area is also called temporary memory area.
It has two parts one for initialize variables and another for non-initialized variables.....All initialized variables are more nearer than non-initialized variables and vice-versa....