I'm currently studying C and im exploring how a generic Binary Tree is implemented and I stumbled upon this example.
I have this node struct:
struct node{const char * value; struct node * left; struct node * right;};
typedef struct node node;
And this function that creates a tree:
node * create_tree(const void * value, node * left, node * right) {
node * root = malloc(sizeof(node));
if (root) {
root->value=value;
root->left=left;
root->right=right;
}
return root;
}
Then this is used in the main as such:
node * root = create_tree("b", create_tree("a", NULL, NULL), create_tree("c", NULL, NULL));
I understand what the result of this is. What I want to make sure I understand is where in memory "b", "a" and "c" end up. From what I understand these are equivalent to a char pointer (since they are in double quotes) and thus my thinking is that the characters 'b' and '\0' are stored on the stack and are pointed to from the heap. Is that what actually happens?
And another question since the struct definition takes a void pointer does create_tree allocate space on the heap based on the argument type once it is called?