. Advertisement .
..3..
. Advertisement .
..4..
The error “control reaches end of non-void function” occurred when I run the C codes. I’ve tried to fix it for some days but have not resolved it yet. Can someone suggest a relevant solution to fix the warning: control reaches end of non-void function c++ issue? Much appreciate your support.
int main(void) {}
As indicated in, the return-type for int is used in the main function.
However, your main function doesn’t return any information. It closes after
Add
It will all work after that.
You can also use a C99 compiler instead of the obvious
return
statement being added tomain()
.C99 allows
main()
to not have areturn
declaration, and the}
implicitly returns 0.Purists will consider this important: not correct the warning by declaring
main()
as returning typevoid
.This warning is identical to that described under Return with no value. GCC assumes that control has reached the end of a function without encountering a return value. This is because the function must return a value. Add a return statement at the end of each function that returns a suitable value even if control is never reached.