The return value from a function is called a temporary. Temporaries only exist for a short time, so if you want to do something with a temporary then you have to do it immediately, before it is destroyed. But you are taking the address of a temporary, which means your program is going to have a pointer to an object which has been destroyed. And so your program is likely to crash.
The way to do this is dynamic memory allocation. Now clearly you are at school or university, so they must be trying to teach you about this topic. It's far too big a topic to explain here, so I suggest you go back to your notes or your favourite C++ book and research dynamic memory allocation.
But quickly here's how to fix your code
tree* newNode(char d)
{
tree* node = new tree; // dynamically allocate a node
node->data = d;
return node;
}
int main()
{
tree* currentNode = newNode(' ');
currentNode->left = newNode(' ');
}
Also your code (and your thinking) would be greatly improved if you sorted out the difference between a node and a tree. They are not the same thing. Your struct tree
is actually a node, so it has completely the wrong name.
BTW, good job paying attention to compiler warning messages. Most newbies don't do that, they're just happy the code compiled. In this case the warning message showed up a serious problem in your code.