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: 0x4008b0
&c:    0x401608

&b:    0x6030a0
&e:    0x6030a8
&cout: 0x6030c0

&a:    0x6031e0
&d:    0x6031e8

&f[0]: 0x1281c20
&g[0]: 0x1281c80

&g:    0x7ffe313b6520
&f:    0x7ffe313b6540

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