Reputation: 1
#include <stdio.h>
int main()
{
printf("hello world");
return 55;
}
I was reading an article that. The return value of main() function shows how the program exited. The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value.
Since I am returning an non-zero value to main function. I assume that it must show errors(because I am not returning 0 to main function), but when i compliled and executed it.It didn't show any errors and it executed normally.Can you please explain it why? In advance thank you
Upvotes: 0
Views: 582
Reputation: 400159
Your assumption is wrong, the surrounding environment (the shell in Linux, command prompt in Windows, your IDE, or whatever you use to start the program) does not by default check the status so nothing happens.
If in Linux, you can do
$ ./myprog
$ echo $?
and you should see 55
.
Update: In Windows, I just learned that you can use errorlevel
:
$ .\myprog
$ echo %errorlevel%
Upvotes: 5