Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on What might happen if I ignore warning?
Post
What might happen if I ignore warning?
#include <iostream>
using namespace std;
int linearSearch(int array[], int n, int key){
for(int i=0;i<=n;i++){
if(array[i]==key){
return i;
}
}
}
int main() {
int balance[] = {10,240,120,150,100};
cout<<linearSearch(balance, sizeof(balance)/sizeof(balance[0]), 150);
return 0;
}
When executing the code I got an warning. Should I really care of warning? I got expected output. Although, I was thinking of warning. What might happen if I ignore warning?
test.cpp: In function ‘int linearSearch(int*, int, int)’:
test.cpp:10:1: warning: control reaches end of non-void function [-Wreturn-type]
10 | }
| ^
When I add return 0;
at end of for loop I don't get the error anymore. The warning was saying that the linearSearch
method (function) wasn't returning always. But, can warning crash my applications?
Replying to last edit of Alexei : My question was about any type of warning not only above one. Above one was just an example. Anyway, I got more accurate answer in the thread
1 comment thread