Warning of "Control may reach end of non-void function"
- by Cloud_cal
I ran a C++ program in Xcode, and encountered a warning of "Control may reach end of non-void function". Here is the code:
Node* search(Node* head, int x)
{
if(!head)
return NULL;
else if(x == head->key)
return head;
else if(x < head->key)
search(head->lchild, x);
else
search(head->rchild, x);
}
I got the same warning when compiling it in Linux, but got the correct result. But in Xcode, the result was wrong. By the way, I got the correct answer and no warning in Visual Studio.