CS253: Software Development with C++

Spring 2018

Memory Segments

See this page as a slide show

CS253 Memory Segments

Segments

Text: executable code

Data: initialized static data

BSS: uninitialized static data

Stack: local variables

Heap: allocated via new

Example

int a, b=45;
const int c = 299'792'458;

int main() {
    static double d, e = 2.7182818284590452353;
    long *f = new long[10];
    vector<int> g = {123,456,789};

    cout << "&exit: " << (void *) &exit  << "\n"
            "&c:    " << &c    << "\n\n"
            "&b:    " << &b    << "\n"
            "&e:    " << &e    << "\n"
            "&cout: " << &cout << "\n\n"
            "&a:    " << &a    << "\n"
            "&d:    " << &d    << "\n\n"
            "&f[0]: " << &f[0] << "\n"
            "&g[0]: " << &g[0] << "\n\n"
            "&g:    " << &g    << "\n"
            "&f:    " << &f    << "\n";
    delete[] f;
}
&exit: 0x400950
&c:    0x401518

&b:    0x603090
&e:    0x603098
&cout: 0x6030a0

&a:    0x6031b8
&d:    0x6031c0

&f[0]: 0x9c72b0
&g[0]: 0x9c7310

&g:    0x7ffedb565d10
&f:    0x7ffedb565d30

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-04-24T16:54

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building