Linkers, Loaders & Executables
When a C main function ends with "return 3;", what generally happens to the value 3?
- AIt is passed to whatever started the program (such as the shell) as the exit status
- B"3" is printed on the screen
- CIt becomes the first argument the next time the program starts
Show answer and explanation
Answer: A. It is passed to whatever started the program (such as the shell) as the exit status
main's return value is passed by the start-up code to exit and reaches the parent process through the OS as the exit status. By convention 0 means success and any non-zero value some kind of failure; in a shell, "echo $?" shows the previous command's exit status. Scripts use this value to decide whether to continue or stop.
- A. Correct. By convention 0 means success and non-zero means failure.
- B. The return value is not printed automatically.
- C. It does not become the next run's argument.