check the following program /*a.c*/ int main() { return 0; } returns 0 to the shell and echo $? gives 0 /*b.c*/ void main() { } echo $? in shell gives some different values for each execution what does it represents????
It represents the fact that you haven't returned a value. The values are meaningless; you should not try to use them if the program doesn't return a value. But you should always return zero from main unless you have a good reason for returning some other specific value; zero indicates success, and for any script calling your program and relying on the return codes to check for errors a garbage return will cause undefined behaviour within the script. If you know for certain that your program will NEVER EVER be called by a script that checks return values, and that returning garbage will definitely have no negative effects, then go ahead and return garbage. Otherwise at least return 0; it's not a difficult line to add. Or return EXIT_SUCCESS; if you prefer.
The current C++ standard mandates that the main() function return int. However you don't have to ACTUALLY return a value. If the control flows out of main without reaching a return statement, it is equivalent to return 0; On the other hand, void main() is ill-formed