Why a warning of “control reaches end of non-void function” for the main function?

Just put return 0 in your main(). Your function main returns an int (int main(void)) therefore you should add a return in the end of it.

Control reaches the end of a non-void function

Problem: I received the following warning:

warning: control reaches end of non-void function

Solution: This warning is similar to the warning described in Return with no value. If control reaches the end of a function and no return is encountered, GCC assumes a return with no return value. However, for this, the function requires a return value. At the end of the function, add a return statement that returns a suitable return value, even if control never reaches there.

source

Solution:

int main(void)
{
    my_strcpy(strB, strA);
    puts(strB);
    return 0;
}

Leave a Comment