ABHINAV RANA - 26 days ago 8
C Question

# Why does pointer value is being used as . instead of -> in this

{
int dest;
};

// A structure to represent an adjacency list
{
};

// A structure to represent a graph. A graph is an array of adjacency lists.
// Size of array will be V (number of vertices in graph)
struct Graph
{
int V;
};

struct Graph* createGraph(int V)
{
struct Graph* graph = (struct Graph*) malloc(sizeof(struct Graph));
graph->V = V;

// Create an array of adjacency lists. Size of array will be V

// Initialize each adjacency list as empty by making head as NULL
int i;
for (i = 0; i < V; ++i)

return graph;
}

// Adds an edge to an undirected graph
void addEdge(struct Graph* graph, int src, int dest)
{
// list of src. The node is added at the begining

// Since graph is undirected, add an edge from dest to src also
}

Specifically

• Ok so the graph is a pointer of type Graph

• hence uses -> to access array which is an object of graph of type AdjList
which has a
pointer of type AdjListNode which is also a pointer.

Since *array member in Graph is a pointer to AdjList then why is

not used ?

I know that
.
operator is used when we access a member of struct which is not a pointer.

somestructpointer -> itsmember

is basically sugar coating

(*somestructpointer).itsmember

I don't understand what's happening. HELP.