Error: control may reach end of non-void function in C

前端 未结 4 765
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 02:12

I cannot figure out why this error is happening: error: control may reach end of non-void function

Here is the code:

bool search(int val         


        
4条回答
  •  情深已故
    2020-12-06 02:37

    Some folks will probably hate this, but....

    bool search(int value, int values[], int n) {
    
       if (n < 1) {
          return false;
       }   
    
       bool ret = false;
       for (int i = 0; i < n; i++) {
          if (values[i] == value) {
             ret = true;
             break;
          }
       }    
       return ret;
    }
    

提交回复
热议问题