title: adjacency matrix implementation in c
body: <p>I am trying to implement a graph using adjacency matrix i am confused in memory allocation of 2d array 
  will it be correct <code>G-&gt;adj=(int**)malloc(sizeof(G-&gt;v*G-&gt;V))</code>
  or the below one is correct </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  struct Graph{
   int V;
   int E;
   int **adj;
  };
  struct Graph* adjmatrix(){
   int u,v,i;
   struct Graph* G=(struct Graph*)malloc(sizeof(struct Graph));
   if(!G)
       printf("Memory Null");
   printf("enter the number of vertex and edges");
   scanf("%d %d",&amp;G-&gt;V,&amp;G-&gt;E);
   G-&gt;adj=(int**)malloc(sizeof(int*)*( G-&gt;V * G-&gt;V ));
   for(u=0;u&lt;G-&gt;V;u++){
       for(v=0;v&lt;G-&gt;V;v++){
           G-&gt;adj[u][v]=0; 
  
      }
  }
  
  for(i=0;i&lt;G-&gt;V;i++){
      printf("reading edge");
      scanf("%d %d",&amp;u,&amp;v);
      G-&gt;adj[u][v]=1;
      G-&gt;adj[v][u]=1;
  
  }
  return G;
  }
  </code></pre>