title: invalid conversion from *void to *int [-fpermissive] using malloc(sizeof())
body: <p>I'm writing a program that calculates the greatest common denominator of two numbers, but i'm getting problem with <code>malloc</code> function and pointers. Actually it's clear how the stack and the heap segments work in the memory and why. But yet i'm not yet able to understand when declaring a pointer and using <code>malloc</code> is functional or not, is necessary or not, in a program. here is the code :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  int *calcolaDivisori(int);
  
  int main(int argc, char** argv) {
  
      int foundCounter = 0;
      int i,j,s1,s2;
      int n1,n2;
      int mcd = 1,mcm;
      int *pn1,*pn2;
      int d1[100],d2[100];
  
      // INPUT dei due interi
  
      printf("Inserisci il primo numero :");
      scanf(" %d", &amp;n1);
      printf("\nInserisci il secondo numero :");
      scanf(" %d", &amp;n2);
  
      // calcolo divisori del primo e del secondo numero e li assegno ai relativi array
  
      pn1 = calcolaDivisori(n1);
      if (!pn1) return 1;
      pn2 = calcolaDivisori(n2);
      if (!pn2) return 1;
  
      for (i=0;i&lt;n1;i++) {
          d1[i] = pn1[i];
      }
  
      for (i=0;i&lt;n2;i++) {
          d2[i] = pn2[i];
      }
  
      free(pn1);
      free(pn2);
  
      // confronto i divisori e calcolo il MCD
  
      s1 = sizeof(d1) / sizeof(int);
      s2 = sizeof(d2) / sizeof(int);
  
      for(i=0; i&lt;s1; i++) {
          for (j=foundCounter; j&lt;s2;j++) {
              if (d1[i] == d2[j]) {
                  mcd*= d1[1];
                  foundCounter = j+1;
                  break;
              }
          }
      }
  
      printf("\n\nIl minimo comune divisore e' : %d", mcd);
  
      return 0;
  }
  
  int *calcolaDivisori(int num) {
      int i;
      int *a = malloc(num * sizeof(int));
      if (!a) return NULL;
      for (i=2;i&lt;num;i++) {
          if (num%i == 0) {
              num/=i;
              a[i-2]=i;
          }
      }
  
      return a;
  }
  </code></pre>
  
  <p>I get the error in the title when is run the command : </p>
  
  <pre><code>int *a = malloc(sizeof(int));
  </code></pre>