Doubts in function type

main()
{ }
When we execute it then why does compiler asks for to return value. While this is the type of “NO argument NO return values” function.

The ISO C++ standard(which most compiler use these days) does not permit main without a return value. So, you must specify int as the return value and return 0 for success and a non zero value for failure as per ISO C++.

1 Like

but why does the compiler not show any error while we execute this function
void main()
{
}

Returning a non-zero value from main is an undefined behaviour, which loosely means that the compiler is free to generate anything when translating your code. In the best case nothing happens or your program simply crashes. But in the worst case the compiler can generate code to wipe your entire hard-disk. The recommended way is to always return int from main. Some compilers may make it safe to return a non int value, such as the Turbo C++, but its not an ISO C++ standard(Turbo CPP does not follow it). The recommended way is to follow the ISO Standard.

2 Likes

Thank so much sir for clearing my doubt.