title: What is the advantage of using memset() in C
body: <p>I was curious as to whether or not there was any advantage in regards to efficiency to utilizing memset() in a situation similar to the one below.</p>
  
  <p>Given the following buffer declarations...</p>
  
  <pre><code>struct More_Buffer_Info
  {
      unsigned char a[10];
      unsigned char b[10];
      unsigned char c[10];
  };
  
  struct My_Buffer_Type
  {
      struct More_Buffer_Info buffer_info[100];
  };
  
  struct My_Buffer_Type my_buffer[5];
  
  unsigned char *p;
  p = (unsigned char *)my_buffer;
  </code></pre>
  
  <p>Besides having less lines of code, is there an advantage to using this:</p>
  
  <pre><code>memset((void *)p, 0, sizeof(my_buffer));
  </code></pre>
  
  <p>Over this:</p>
  
  <pre><code>for (i = 0; i &lt; sizeof(my_buffer); i++)
  {
      *p++ = 0;
  }
  </code></pre>