Questions about address spaces in C++
<p>Please read the following C++ code and the results. According to some wiki pages, static, automatic and dynamically-allocated variables are allocated in different address spaces, namely, data segment, stack and heap. However, it seems to me that the address of static and dynamic variables are at about the same place. Why is that so? How do I know the static variable is really in data segment, not in heap?</p>

<p>A more broad question is whether it is possible in C++ to know the range (or available size) of each address space?</p>

<p>Another question I have is why the address of volatile variable is 1?</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
static int i;
int main() {
    cout &lt;&lt; sizeof(int*) &lt;&lt; endl;
    int j;
    int* k = new int[10];
    volatile int l;

    cout &lt;&lt; &amp;i &lt;&lt; endl;
    cout &lt;&lt; &amp;j &lt;&lt; endl;
    cout &lt;&lt; k &lt;&lt; endl;
    cout &lt;&lt; &amp;l &lt;&lt; endl;

    delete[] k;
}
</code></pre>

<p>Results:</p>

<pre><code>8
0x1000010e4
0x7fff5fbff66c
0x100100080
1
</code></pre>
