I'm learning structs in C and trying to make a binary tree. Here's the tree struct:
struct BinaryTree
{
int data;
struct BinaryTree *left;
struct BinaryTree *right;
};
typedef struct BinaryTree BinaryTree;
void addTreeNode(int element, BinaryTree *tree);
int main(int argc, const char * argv[])
{
BinaryTree tree;
addTreeNode(2, &tree);
return 0;
}
Now here's what I don't understand:
void addTreeNode(int element, BinaryTree *tree)
{
*tree = {element, NULL, NULL};
}
I am not trying to do anything useful inside this function for now, but I don't understand why I get a parsing issue at this line. As far as I understand I take a pointer to a tree, dereference it and initialize it. Why the compile error?