Amazon Interview Question
Software Engineer / DevelopersNishant is correct.
There are two types of Data Segments
1. Uninitialized data segment(block started by symbol -bss). Whenever you declare a static variable or global variable, and do not initialize it, they are automatically initialized to 0 or NULL and stored here
2. Initialized Data Segment - All static or global variables that you initialize are stored here
Someone said "extern - data segment" which is sort of incorrect. Actually, for extern variables memory is not allocated at that time ( Assuming that it would be allocated some where else where the object is actually defined ). That would be a global object in general ( although I couldn't think of any other alternative, I won't commit on it ). Thats the reason why that particular object will go to data segment( if initialized ) or bss (if uninitialized ).
the variables are stored like..
- xmagics June 23, 2008auto - stack
static - data segment
register - cpu registers
extern - data segment
also memory we allocate dynalically using malloc etc is created using heap.
and out program is stored into code segment..
..
hope it will help :)