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]: 0x16072b0
&g[0]: 0x1607310

&g:    0x7ffc0d449550
&f:    0x7ffc0d449570

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