c - Is returning zero from main necessary, and how can the return value from main be useful? -
i know it's been convention in c89 return 0 integer value main in c program, this:
int main() { /* useful here */ return 0; }
this return "successful" result operating system. still consider myself novice (or intermediate programmer @ best) in c, date i've never understood why important.
my guess is, useful return result if you're tying output of program input of another, i'm not sure. i've never found useful, or maybe don't understand intention is.
my questions:
- is returning 0 necessary c program?
- how return value
main()
useful?
when writing scripts (like in bash, or cmd.exe on windows) can chain commands && , || operators.
canonically, a && b
run b
if result of a
zero, , a || b
run b
if a
returned nonzero.
this useful if wish conditionally run command if previous 1 succeeded. example, delete file if contains word foo. use :
grep foo myfile && rm myfile
grep
returns 0 when there match, else nonzero.
Comments
Post a Comment