title: What happens when I assign long int to int in C?
body: <p>In a recent homework assignment I've been told to use <code>long</code> variable to store a result, since it may be a big number.</p>
  
  <p>I decided to check will it really matter for me, on my system (intel core i5/64-bit windows 7/gnu gcc compiler) and found out that the following code:</p>
  
  <pre><code>printf("sizeof(char) =&gt; %d\n", sizeof(char));
  printf("sizeof(short) =&gt; %d\n", sizeof(short));
  printf("sizeof(short int) =&gt; %d\n", sizeof(short int));
  printf("sizeof(int) =&gt; %d\n", sizeof(int));
  printf("sizeof(long) =&gt; %d\n", sizeof(long));
  printf("sizeof(long int) =&gt; %d\n", sizeof(long int));
  printf("sizeof(long long) =&gt; %d\n", sizeof(long long));
  printf("sizeof(long long int) =&gt; %d\n", sizeof(long long int));
  </code></pre>
  
  <p>produces the following output:</p>
  
  <pre><code>sizeof(char) =&gt; 1
  sizeof(short) =&gt; 2
  sizeof(short int) =&gt; 2
  sizeof(int) =&gt; 4
  sizeof(long) =&gt; 4
  sizeof(long int) =&gt; 4
  sizeof(long long) =&gt; 8
  sizeof(long long int) =&gt; 8
  </code></pre>
  
  <p>In other words, on my system, <code>int</code> and <code>long</code> are the same, and whatever will be too big for <code>int</code> to hold, will be too big for <code>long</code> to hold as well.</p>
  
  <p>The homework assignment itself is not the issue here. I wonder how, on a system where <code>int &lt; long</code>, should I assign an <code>int</code> to long?</p>
  
  <p>I'm aware to the fact that <a href="https://stackoverflow.com/questions/12501331/how-does-long-to-int-cast-work-in-java">there</a> <a href="https://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java">are</a> <a href="https://stackoverflow.com/questions/1161887/what-happens-if-i-cast-a-double-to-an-int-but-the-value-of-the-double-is-out-of">numerous</a> <a href="https://stackoverflow.com/questions/2711522/what-happens-if-i-assign-a-negative-value-to-an-unsigned-variable">closely</a> <a href="https://stackoverflow.com/questions/7977265/what-happens-at-background-when-convert-int-to-float">related</a> questions on this subject, but I feel that the answers within these do not provide me with the complete understanding of what will or may happen in the process.</p>
  
  <p>Basically I'm trying to figure out the following:</p>
  
  <ol>
  <li>Should I cast <code>long</code> to <code>int</code> before the assignment, or <del>since <code>long</code>
  is not a different data type, but merely a modifier,</del> it will be
  considered unharmful to assign directly?</li>
  <li>What happens on systems where <code>long &gt; int</code>? Will the result be
  undefined (or unpredictable) or it will cause the extra parts of the
  variable to be omitted?</li>
  <li>How does the casting from <code>long</code> to <code>int</code> works in C?</li>
  <li>How does the assignment from <code>long</code> to <code>int</code> works in C when I don't
  use casting?</li>
  </ol>