static memory in a C program

I am a little confused about the memory management of a C program.  When a C program is loaded into main memory, do statically initialized variables get loaded into the initialized data segment, or onto the stack.
For example if I have the program,
int globx = 1;
int y;
int main (){
static int x = 10;
return 0;
}
I know globx is in the initialized data segment, but is x as well?
Also, do you know where y would get put?  I have the understanding that y would not be in object file.  If you have a good understanding of how memory is arranged and how it is loaded into memory could you please clear this up for me.
Thank you,
K
KayodeCS_BUAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stehanCommented:
Hi !

I don't know what you mean with 'initialized data segment'.

This is what I do know:

globx and y are global variables, they are known to all functions you'll create in your program. Space will be reserved on the stack until the program is finished.

Defining x as a static in the function main() means that it is a local variable whose value will not be changed if you pass it to a function (even by reference).

If you had defined x as static outside main(), lets say directly after int y, it would have become a variable only known to functions in the same file, to which it would look as a global variable. But functions defined in a different file would not know it.

Hope this helps.
0
sarda_rameshCommented:
In C memory management deals basically with two types:

1. On Stack
2. On Heap.

http://www.cs.huji.ac.il/~plab/lectures/Class3.pdf

check this out .. it will probably answer your queries and clear your concepts

regards
ramesh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KayodeCS_BUAuthor Commented:
Thank you, I think I got it now.  The static variable x would be stored in the initialized data segment.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

rajeev_devinCommented:
There is no such concept called initialized data segment. When you compile the code fragment the compiler is going to allocate the memory in two different ways:

1. For globalx, and y , compiler is going to allocate memory for them in data segment.
2. and for others, in the function, the memory will be alloocated during run time within the stack (your int x).

Since you are providing the value of globalx, it will be initialized by the compiler itself. But there is no difference between the allocation of globalx and y.

Hope this may help you.
0
rajeev_devinCommented:
There is no such concept called initialized data segment. When you compile the code fragment the compiler is going to allocate the memory in two different ways:

1. For globalx, and y , compiler is going to allocate memory for them in data segment.
2. and for others, in the function, the memory will be alloocated during run time within the stack (your int x).

Since you are providing the value of globalx, it will be initialized by the compiler itself. But there is no difference between the allocation of globalx and y.

Hope this may help you.

Give further comments...
0
WaffleSouffleCommented:
I'm a bit out of touch, but I believe they are loaded into the initialised data segment, and the order they occur in may depend on initialisation (initialised first, unintialised later ???). Seem to remember a description of this in petzold's original windows programming book but I could be way off
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.