To be a good programmer is very necessary to understand the memory structure.
(1) What is memory cell?
Entire RAM has divided in number of equal part, which is known as memory cell.Capacity of each cell is to store one-byte data.
i.e char a reserve one memory cell while float a reserve four memory cell.
Each memory cell has unique address.Address are always in whole number an increasing order.
(2) What is residence memory?
RAM has divided into two parts:
(1) Extended memory (useless)
(2) Residence memory :
When any program is executed it is stored in the residence memory .For turbo c, it has 1MB residence memory i.e when we open turbo c it store 1MB in the RAM.
(3) What is physical address ?
20 bit address of the memory cell is known as physical address or real address.In 20 bit we can represent address from 0x00000 to 0xFFFFF.
(4) What is segmentation?
Residential memory of RAM of size 1MB has divided into 16 equal part.These part is called segment.Each segment has size is 64KB.
This process of division is known as segmentation.
(5) What is necessity of segmentation?
Physical address are 20 bit.But we have no pointer of 20 bit.So pointer can not access whole residential address .So to solve this problem we have three different pointer and segmentation has done.
(6) What is offset address?
Each segment has divided into two parts.
1. Segment no (4bit)
2. Offset address (16 bit)
Each segment has same offset address but different segment number.
Suppose physical address is 0x500F1
Then it’s segment number is 5 and offset address is 00F1.
(7) Write a program to find the offset address of any variable?
Void main ()
Note. %p is used to find the offset address (in hexadecimal) of any variable.
(8) What is data segment?
Segment number 8 has special name which is known as data segment.
It has divided into four parts.
1. Stack area:-
All automatic variables are created into stack area.Default storage class of any local variable is auto.This variable may be int, char, float, array, pointer, struct, union etc.It also return function argument and return address.It follow LIFO data structure. It has two part one for initialize variable another for non-initialize variable.All initialize variable are more nearer than uninitialized variable and vice versa.
2. Data area :
All static and extern variable are created in the data area.
3. Heap area:
Malloc and calloc always allocate memory in the heap area.It is used for dynamic memory allocation.It’s size depends upon free space in the memory.
4. Code area:
Function pointer can only access code area.Size of this area is always fixed and it is read only area.
(9) What will output:
Output: 7 6 5
Default storage class int a=5 is auto.Since it automatic variable it will create in the stack area.
It will store in the stack as
Stack always follows LIFO data structure.
In the printf statement name of variable is not written explicitly.So default output will content of
Stack which will be in the LIFO order i.e 7 6 5.
(10) what will be output:
int a=5 ,b,c=7;
printf(“%d %d %d”);
Output: 7 5 garbage value
Automatic variable a and c has initialized while b has not initialize.Initialize variable are more nearer than non initialize variable .They will be stored in the stack .So due to LIFO first output will be 7 then 6 (since a is more nearer than b with respect to c) then any garbage