Linkers, Loaders & Executables

When a C main function ends with "return 3;", what generally happens to the value 3?

  1. AIt is passed to whatever started the program (such as the shell) as the exit status
  2. B"3" is printed on the screen
  3. 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.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What happens when the strip command is applied to an executable?
  2. How does a linker treat a weak symbol?
  3. What is the main purpose of name mangling, in which a C++ compiler encodes argument types and other information into symbol names?
  4. What is the most suitable use of Linux's dlopen function (the counterpart of Windows LoadLibrary)?
  5. When 100 processes use the same shared library, how is physical memory used?