I'm having some trouble dereferencing a pointer to a pointer. I have a node e
that I put onto the heap and also another node called List
. List
is a pointer pointing to e
.
For some reason I am having a segmentation fault when I am dereferencing e
through List
:
struct ELEMENT{
int key;
int edge;
struct ELEMENT *adjList;
};
int numOfNodes = 3;
struct ELEMENT *e = (ELEMENT*)malloc(numOfNodes * sizeof(struct ELEMENT));
// e is now on the heap
struct ELEMENT **List = (ELEMENT**)malloc(numOfNodes * sizeof(struct ELEMENT));
// List (pointer to e) is now on the Heap
List[1]->key = 5; // segmentation fault occurs here