Compile and run a C program

C is a compiled language that requires another program to convert the source code to object code which is understood by the computer. This program is known as compiler.

So to compile a C program, we need a compiler. A few popular compilers are: GCC, Turbo C/C++.

To set up a C language compiler, there are three ways:

  • To download a full fledge IDE(Integrated Development kit) like Turbo C or Microsoft visual C++, which comes along with a C language compiler.
  • Use any text editor to write a program and download the C compiler separately.
  • Use some online IDEs like or

In this we will be looking at the second and third options to compile a C program.

Without an IDE:

  • First, a C compiler called GCC needs to be downloaded from the gcc website
  • Once it is downloaded and installed, a program can be written on any text editor and saved with the extension .c like
  • Open a command prompt or a terminal(for Linux or MAC OS) and go to the directory where the program hello_world is saved.
  • Type in the command gcc hello_world.c to compile the code. This will compile the code and result in an executable with the name a.out(default name), if there are no errors.
  • Now, to run the program, type in ./a.out, and you will see Hello World displayed on the screen.

Using online IDE:
This is the easiest way to compile and run a C program.

Step 1: Visit the website
Visit the link and select the programming language as C.

Step 2: Write your program
By default, a hello world program is already written as a skeleton for all C programs. This can be modified or extended to add to your logic.

Step 3: Run the program
In this on-click run, it compiles and runs. If there are no errors a Hello World is written on the below output screen.

Step 4: Save the program
Create a login and save the program with the appropriate name for future reference

Difference between Compiling a program and running a program:
There are two steps first is to compile a program that is look for any syntactical errors in the code and if not produce the machine code which can be understood by the system. This involves use of another program called a compiler to do so.

The second steps is to run the executable (machine code) that is to execute the statement inside the main.

Diag-1: C program Execution steps

This image has an empty alt attribute; its file name is image-1.png

Related Posts:

Categories: C Language

4 replies


  1. Features of C programming language - Tech Access
  2. Phase of C program Compilation - Tech Access
  3. Introduction to C Programming Language - Tech Access
  4. C Language Basic Syntax Rules - Tech Access

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: