title: Initializing an integer array using memset and an int value - fails
body: <p>I am writing host code for a CUDA program, so I am stuck using standard C functions.  I am having a problem with initializing the elements of an integer array using the <code>memset</code> function.  I was under the impression you could use <code>memset</code> to initialize an integer array to, for example, all 4s like this:</p>
  
  <pre><code>int num_elements = 10;
  int* array_example = (int*)malloc(num_elements * sizeof(int));
  memset(array_example, 4, sizeof(array_example));
  </code></pre>
  
  <p>But when I do this, it sets each byte, not each <code>int</code>, to 4.  If I say:</p>
  
  <pre><code>memset(array_example, 4, 1);
  </code></pre>
  
  <p>I get a 4 in the first integer and if I say:</p>
  
  <pre><code>memset(array_example, 4, 2);
  </code></pre>
  
  <p>I get 1024 in the first integer and 0 in the second.  I understand the <code>memset</code> function  sets the number of bytes specified in the third parameter to 4, but is there any way to use memset to set each integer to 4 instead of each byte?  Otherwise, am I stuck using a for loop?  My GPU has a low compute capability so I don't have access to some of the nicer CUDA additions that allow more C++ usage.</p>