$?     - contains the most recent exit code in the parent shell

Typing 'exit' in a login shell will log out the user. If it is typed in a terminal, that terminal will be closed. Ctrl-D has the same effect in a terminal.