Warning of "Control may reach end of non-void function"

Posted by Cloud_cal on Stack Overflow See other posts from Stack Overflow or by Cloud_cal
Published on 2013-10-23T03:33:02Z Indexed on 2013/10/23 3:53 UTC
Read the original article Hit count: 126

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about xcode