gcc main.c -g -ansi -c gcc stuff.c -g ansi -cThe -c compiler option tells the compiler to compile the source code into object code, but not to create an executable. By default, the object code filenames are the same as the source code filenames with the ".c" replaced with a ".o": main.o and stuff.o in our case.
gcc main.o stuff.o -o myprogramThe C compiler doesn't actually do the linking; it just calls the linker ld and adds on the standard C libraries to the list of things to be linked. The command that is "really" happening is:
ld -o myprogram /usr/lib/crt1.o main.o stuff.o -lcThe -lc specifies that the standard C library, containing printf, scanf, atof, malloc, isalpha, malloc, and other "built-in" functions is to be linked in. We've seen the -l linker command before, when we used -lm: in both cases, the -l* is expanded to /usr/lib/lib*.a, so for example, -lc causes the /usr/lib/libc.a.
/usr/lib/crt1.o is a bunch of extremely low level, language independent routines. That is, it is linked with not only C programs, but also Pascal programs, FORTRAN programs, etc. It contains the routines that handle the command line arguments, call main, and then clean things up when main ends. This routine which cleans things up is called exit, so that is why you can call exit to terminate your program.