Dynamically Allocating Array of Pointers to a Struct
So I have a binary tree, and I'm trying to store the memory addresses of those nodes into a dynamically allocated array.
So I'm starting off by allocating the memory for the array (hope that is correct)
struct node *arr = NULL;
arr = (struct node*)malloc(sizeof(struct node) * matching);
Then I pass this array into another function to do the recursive work of traversing the binary tree in prefix order. However, when I try to store the memory address of the struct into an index of the array, it gives me a compile error.
(arr[*index]) = &given_tree;
Posted Apr 18, 2022, 7:52 PM UTC
310