C++ control reaches end of non-void function
control reaches end of non-void function
If you have received the error message “control reaches end of non-void function” don’t worry the fix is probably going to be pretty easy. This just means that the function specifies a return type and you didn’t include a return statement at the end of your function. Unless a function is void it needs to return a value.
Here are three potential fixes:
- Add a return statement at the end of the function.
- Change the return type to void.
- Make sure control never reaches the end of the function.
The fix is probably going to be adding a return statement at the end of the function. This is an example of a working function with a return statement.
#include <iostream>
int main() {
std::cout << "test";
return 0;
}