variable storage

K

kanalkannan

Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.
 
I

Ian Collins

kanalkannan said:
Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.
The answer lies in your compiler documentation, none of the above are
standardised.
 
S

santosh

kanalkannan said:
Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.

These details are specific to the compiler and it's target system.
 
W

Wang Jiaji

Hi,
I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

waiting for reply.

They're compiler specific and not very important, you can create your
own segment, with any name you like.
 
K

Keith Thompson

Wang Jiaji said:
They're compiler specific
True.
and not very important,

Probably true, though they might be important in some contexts.
you can create your
own segment, with any name you like.

Oh? C has no concept of "segments". Any mechanism for creating your
own would be extremely system-specific.
 
R

Randy Howard

Oh? C has no concept of "segments". Any mechanism for creating your
own would be extremely system-specific.

int segment; /* this is my segment, there are many like it
* but this one is mine.
*/
 
U

user923005

Hi,
        I have heard a question in C data storage i want to know where
the auto,static and global variables are get stored and what are the
memory segments like stack heap and its allocation.

All auto variables are placed into automatic storage.
All variables allocated with malloc() or calloc() are placed in
allocated storage.
All variables that are static or global have static duration.

Stack and heap do not appear in the standard. Many compilers place
automatic storage on a stack. Many compilers place allocated storage
on a heap. From the C language's perspective, understanding of the
physical location is not necessary to use the memory. There is no
imporant reason that all three types of storage could not be in the
same type of physical structures and general locations.

If you really want to know where something resides, take the address
of it (unless it is already an address) and (after casting to void *)
print the address with a %p format specifier. That will tell you
where the variable is located. Of course, it could be a symbolic
address running in a virtual machine, but that's neither here nor
there. You would get the compiler's view of where the data lives
exactly in any case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top