Skip to main content

Posts

Showing posts with the label The Crazy Programmer Solve “control reaches end of non-void function” Error Solve “control reaches end of non-void function” Error The Crazy Programmer

Solve “control reaches end of non-void function” Error Neeraj Mishra The Crazy Programmer

Hello everyone, In this article, we are going to discuss a common problem faced by beginners and also experienced programmers. Often when we run into the warning saying warning: control reaches end of non-void function . Generally, we ignore this error because most of the time as the program still runs the same even if this warning is coming. Let’s first see a simple example then this kind of error can occur. #include <bits/stdc++.h> using namespace std; int fun(){ if(false) return 0; } // Error here int main() { fun(); return 0; } If we run this c++ code it works fine and terminates but we get an error at the 8th line saying control reaches end of non-void function. To understand this error we first have to understand the working of the compiler a bit in detail. There are two important kinds of error which occurs while running a program. Compile-time error: Error which can be identified by the compiler without running the program. General