Introduction to Computer Science, Fall - 2003

Compiling and running C programs

Assume that the C program you have written is in the file named hello.c
Remember that a C program file name should end with an extension .c in general. The file that include the C program (in our case the file hello.c) we will call a source file or source code.

I assume that you have logged in to the computer and are currently in the UNIX shell. I will omit the UNIX prompt for clarity. First, you should compile your program with the following command:

gcc hello.c

This command will invoke the GNU ANSI C compiler gcc which will create a file named a.out ( this is the executable file/code). Now to run the program, simply type:

a.out

Then, your program will run.

It's a good practice to get into the habit of naming your executable files with descriptive names. For example,

   gcc -o helloExe hello.c
will compile the program hello.c and produce the executable in a file named helloExe. You can run the executable program as follows:
   helloExe