To be a good programmer is very necessary to understand the memory structure.

Memory organization

(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 ()
int x;
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:

void main()
int a=5,b=6,c=7;
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:
void main()
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


Anonymous said...

very nice.... carry on ur works,,,,

Anonymous said...

ausumn work plz carry on n help the students

rakesh said...

Excellent Keep it on........

Anonymous said...

good information.keep it up.

Ghanshyam said...

realy,different info........

Ragavendra Ramalingam said...

hi why we are using BSS segment it's also come's under data segment.

Honey said...

excellent work

Anonymous said...

really great work....

gourab said...

Hats off to ur knowledge bro....keep it up.......

Anonymous said...

thanks.. its very helpful.. :)

raj said...

ultimate very informative ......... nice work keep it up :)

Sankaranarayanan said...

Its reallly really good good please give more information likes this

Anonymous said...

nice buddy...!!

misaly said...

very nice work,a very very useful site

Anonymous said...

nice work ........!!!!!!

Anonymous said...

nice info

Harry said...

first time i read this things ....

Anonymous said...

very good!!!

chotadon said...

very informative,thanks a lot!!!

Anonymous said...

very helpful.thanks!1

Mr. devendra tiwari said...

nice job dear....keep it on....this is very useful for us.

amit singh said...

Really gr8 work!! hats off dude..

amit singh said...

Really gr8 work !! hats off dude ..

amit singh said...

Really gr8 work !! hats off dude ..

amit singh said...

Really gr8 work !! hats off dude ..

amit singh said...

Really gr8 work !! hats off dude ..

Anonymous said...

m just luvin to clear ma concepts this site. gr8 work.

Rohan said...

It was really helpful.thanks a lot

@rvind said...

the program given above is not working there any platform problem ..i am using DEV C .

Anonymous said...

yeah same prob here..
i am using dev cpp
and i got o,garbage value,garbage value..

laukik said...

thanks for sharing such a great information

Anonymous said...

awesome knowledge :) Every Day a new information.

matheen smart vip said...

clear meaning about segments

Nil said...

very clearly understood the concept.Thanks a lot .....

Pankaj Tirpude said...

what about this code..#include
int main()
int x;
return 0;

o/p: 65524

Kamlesh Patel said...

Its Excellent! Basics of pointer describe in easy to understand in a good way.

Keep it up....

palash said...

thank you

Asha Devi said...
This comment has been removed by the author.
Jitendra Singh said...

nice work sir

Jitendra Singh said...

sir please explain how function call work in c using stack

laxmi ullagaddi said...

Very good explaination...!!! Thanks you very much

barkhasen said...

Thanks Sir for this explanation...It helps..!!