title: Dynamically allocation memory for array of structs in c
body: <p>I have two structures as shown below</p>
  
  <pre><code>struct server{
      // some members
  };
  
  struct msg{
      struct server* servers;
  };
  </code></pre>
  
  <p>Then I do this.</p>
  
  <pre><code>struct msg msg1;
  struct server s1,s2;
  
  msg1.servers = (struct server *)malloc(2*sizeof(struct server));
  msg1.servers[0] = &amp;s1; // compilation error 
  msg1.servers[1] = &amp;s2;  // compilation error
  </code></pre>
  
  <p>This code does not compile and giving the following error : incompatible types when assigning to type ‘struct server’ from type ‘struct server *’.</p>
  
  <p>What am I doing wrong?</p>