I am implementing graphs using adjacency matrix, but I am unable to solve the segmentation fault. Can anyone help me in guiding dynamic allocation of two dimensional matrix? I also want to know how is 2-D array stored in memory and how it is accessed.
#include<stdio.h>
#include<stdlib.h>
struct Graph{
int V; // To represent number the vertex...
int E; //To represent number the Edge.....
int **Adj; // Two dimensional matrix to form the adjacency matrix... 
};
struct Graph *adjMatrixOfGraph(){
        int i;    //for scanning the edges between them .... 
        int u,v; // for loop while initliasing the  adjacency matrix... 
        struct Graph *G=(struct Graph*) malloc(sizeof(struct Graph)); //
        if(!G){
        printf("Memory Error");
        return;
        }
        printf("Number of Vertices");
        scanf("%d",&G->V);
        printf("%d",G->V);
        printf("Number of Edges");
        scanf("%d",&G->E);
        G->Adj=(int **)malloc(sizeof(G->V * G->V)); //allocating memory for G->Adj);
        /*Dynamic memory allocation for Two Dimensional Arrays */
/*      G->Adj = malloc(G->V * sizeof(int )); 
            if(G->Adj == NULL) {         
                 printf( "out of memory\n");     
                }     
         for(i = 0; i < G->V; i++) {     
                G->Adj[i] = malloc(G->V * sizeof(int ));     
                if(G->Adj[i] == NULL) {         
                printf( "out of memory\n");     
                } 
                }
*/
        if(!G->Adj)
        {
        printf("Memory Error");
        return;
        }
        for(u=0;  u < G->V; u++){
        for(v=0; v < G->V; v++){
         //printf("%d %d",u,v); 
         G->Adj[u][v]=0;  //initalising the complete adjacency matrix to zero.
        }
        }
        //Enter the edges.. and the vertices.
        //We are considering this graph as undirected one ... 
        for(i=0;i< G->E;i++)
        {
        scanf("Reading Edges %d %d ",&u,&v);
        G->Adj[u][v]=1;
        G->Adj[u][v]=1;
        //if this graph was directed then we should have considere only one side... 
        //G->V[u][v]=1;
        }
return G;
}
main()
{
struct Graph *G1=adjMatrixOfGraph();
//struct Graph *adjMatrixOfGraph(){
printf("Successful");
return 0;
}
 
     
     
     
    