C vs C++ sizeof : <p>I just came across this simple code snippet and am wondering why output of this program when it's compiled by a C compiler is <code>4</code> and when it's compiled by a C++ one is <code>8</code>.</p>

<pre><code>#include &lt;stdio.h&gt;

int x;

int main(){
    struct x {int a; int b;};
    printf("%d", sizeof(x));
    return 0;
}
</code></pre>

<p>C++ output is rational (<code>8 = 4 + 4 = sizeof(x.a) + sizeof(x.b)</code>), but output of C isn't. So, how does <code>sizeof</code> work in C?</p>

<ul>
<li>C : <a href="https://ideone.com/zj5Qd2">https://ideone.com/zj5Qd2</a></li>
<li>C++ : <a href="https://ideone.com/ZZ4v6S">https://ideone.com/ZZ4v6S</a></li>
</ul>

<p>Seems C prefers global variables over local ones. Is it right?</p>
