Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Post History

42%
+1 −2
Q&A 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 ...

2 answers  ·  posted 3y ago by Anonymous‭  ·  last activity 3y ago by Lundin‭

#4: Post edited by user avatar Anonymous‭ · 2021-08-31T06:22:09Z (about 3 years ago)
  • What might happen if I ignore the return-type warning?
  • What might happen if I ignore warning?
  • ```c++
  • #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?
  • ```c++
  • 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](https://stackoverflow.com/questions/22742581/warning-control-reaches-end-of-non-void-function-wreturn-type#22742601) always. But, can warning crash my applications?
  • ```c++
  • #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?
  • ```c++
  • 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](https://stackoverflow.com/questions/22742581/warning-control-reaches-end-of-non-void-function-wreturn-type#22742601) 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](https://software.codidact.com/comments/thread/4280)
#3: Post edited by user avatar Alexei‭ · 2021-08-30T16:48:59Z (about 3 years ago)
added relevant tag + simplified the title
  • Should I really care of warning? What might happen if I ignore warning?
  • What might happen if I ignore the return-type warning?
#2: Post edited by user avatar Anonymous‭ · 2021-08-30T16:31:15Z (about 3 years ago)
  • ```c++
  • #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?
  • ```c++
  • test.cpp: In function ‘int linearSearch(int*, int, int)’:
  • test.cpp:10:1: warning: control reaches end of non-void function [-Wreturn-type]
  • 10 | }
  • | ^
  • ```
  • ```c++
  • #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?
  • ```c++
  • 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](https://stackoverflow.com/questions/22742581/warning-control-reaches-end-of-non-void-function-wreturn-type#22742601) always. But, can warning crash my applications?
#1: Initial revision by user avatar Anonymous‭ · 2021-08-30T16:28:03Z (about 3 years ago)
Should I really care of warning? What might happen if I ignore warning?
```c++
#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?

```c++
test.cpp: In function ‘int linearSearch(int*, int, int)’:
test.cpp:10:1: warning: control reaches end of non-void function [-Wreturn-type]
   10 | }
      | ^
```