title: How to write exact 1MB array in C?
body: <p>I want to initialize an array of size 1MB. So my goal is finally write that 1MB to a file. 
  I am curious every time i use this formula it is giving less than 1mb. </p>
  
  <pre><code>int len = (1048576)/sizeof(int);
  data = (int *) malloc(len);
  </code></pre>
  
  <p>What is correct way ? 
  Thank you</p>
  
  <hr>
  
  <p>Edit - As per the comments I have changed the code . </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;mpi.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[]) {
      int *data;
      int bytes = (1024*1024);
      data = (int *) malloc(bytes);
      for(int i=0;i&lt;bytes;i++){
       data[i] = (int)rand();
       printf("%d",data[i]);
      }
      return 0;
  
  }
  </code></pre>
  
  <p>After compiling it and I tried dumping the data like below </p>
  
  <pre><code> mpicc -o a mpiFileSize.c
  
   ./a &gt; dump.dat
  </code></pre>
  
  <p>Now I see the file size of dump.dat. Why its 2.5MB ?
  <a href="https://i.stack.imgur.com/3JzcU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3JzcU.png" alt="File Size in Mac"></a></p>