w3resource logo

C Programming

Compile and execute C program in Linux and Windows

Secondary Nav


In this document, we will see how we can compile and execute C program in Linux and Windows.The document also contains a list of C compilers available.

We will see how to compile using Visual C++ 2008 Express Edition, Turbo C++, wxDev-C++ in Windows. For Linux and Unix operating systems, we will be using GNU Gcc to compile C program. Both of these are free.


Install, compile and execute C program with Visual C++ 2008 Express Edition with SP1 in Windows

Download and install

To download, point your browser to http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express and select Language and click on Free Download. After you complete download, run the executable file, it will ask you to select whether you want to install some other optional products, uncheck those options so that you can install only the product required. The installation process will start downloading other files from the Microsoft site and depending upon your connection speed it will take a while to complete the installation.

visual c++ 208 express edition

Once the installation is complete, in Windows 7, start the Visual Studio 2008 Command Prompt from All Programs > Microsoft Visual C++ 2008 Express Edition > Visual Studio Tools > Visual Studio 2008 Command Prompt.

visual studio command prompt

Write, compile and execute your first program

Step 1 : type notepad demo.c (you can replace the filename with your own) and press Enter, when asked if you want to create a new file, say yes.

visual studio command prompt prompt

Step 2 : type the following code and click File > Save . When asked where to save the file, select the location suitable.

Step 3 : Type cl sample.c and press enter now. This will compile the program to create an executable file (.exe).

compile C program Windows 7

Step 4 : Now simply type the name of the file sample and enter. That will show you the output.

Output C program Windows 7

Install, compile and execute C program with Turbo C++ in Windows

Obtain and install

Turbo C++ is very popular C compiler and IDE. The problem is, Borland, the creator organization of the compiler and IDE does not provide any option to download the compiler and IDE. But if you google with "turbo c++ download", you will get plenty of sites to download the compiler and IDE. There are three files to download - TC.exe, tc.r00 and tc.r01. After downloading, run TC.exe file it will create a folder TC at the end the installation process. To run turbo C++, enter bin directory within TC and look for tc.exe. Double click the tc.exe file and turbo C++ IDE will open.

Run Turbo C++ in full screen in Windows 7

Those who are running Turbo C++ is Windows 7, when the IDE is opened, click on "Ignore" in the popup window saying that it does not support full-screen mode. Now, click on the top left corner of the Turbo C++ window and select "Properties" . Select "Font" tab and change the font to "Lucidia Console" from default "Raster fonts". Also, change the font size to "28". Now select "Layout" tab and set "width" as 80 and "Height" as 25 under "Screen Buffer Size". Under "Window Size", change "Width" as 60 and "Height" as 25. Under "Window Position", set the value of "Left" and "Top" both as -4. Make sure "Left System Position Window" is unchecked. Click "Ok" to close the properties window. Now you can see the Turbo C++ IDE in full screen.

turbo c++ window

Write, Compile and Run C program

Open a new file from File > New in the Turbo C++ IDE. Write a small program in the IDE.

Now go to File > Save As and save the program with the filename of your choice (make sure extension of the filename is .c).

Click on Options and go to Directories. Click on Directories and set Output Directory as you want and Source Directory as where you have saved the C program file.

Now go to compile and click on Compile. And then Click on Run. You will see the output of your C program.

Write, Compile and Run C program using wxDev-C++ in windows

wxDev-C++ is easy to use IDE which you may opt for to write C Program. You may download the installer from wxdsgn.sourceforge.net. We found it working perfectly on Windows 7 and Windows XP. It also installs MinGW along with and you don't need to set any environment variables. The default compiler for this IDE is gcc.

After downloading the installer, run the exe file by double clicking on it and an installation wizard will guide you to install. Once you finish the installation, you start it from Programs and the first time when you run it, it takes a while for parsing header files. The IDe window looks like following:

wxDev-C++ IDE Window

You may start programming by clicking on File > New > Source File in the window. Note that while saving the file, you must select file type as C as this IDE supports C++ also.

wxDev-C++ IDE Window

You may use F9 or as shown below to Compile and Run program.

wxDev-C++ IDE Window

When compilation is done, it opens a new window to show you output.

wxDev-C++ IDE Window

If you have errors, it shows you in the pane below like following.

wxDev-C++ IDE Window

Though slightly dated, we find wxDev-C++ an excellent IDE for programming C. You may try it if you are using Windows.

Install, compile and execute C program in Linux

Most of the time, when you are installing Linux, GNU Gcc compiler is already installed. If not, run the following command (our system is Ubuntu Linux) :

c install linux

If C compiler is already installed, it will show you a message like above. If not, it will install all the necessary packages.

Now open a text editor and write a small C program like following and save it as demo.c :

#include <stdio.h>
printf("Welcome to C Programming");

Now run the command as shown below to compile and execute the file :

c-program run linux

This how you can install GNU Gcc compiler, write a C program and run it under Linux.

List of the C Compilers

The following table is a list of the C compilers available. This is not a complete list but this will give you a fair idea about various C compilers, which OS / Platform they support and whether it has a programming environment.

Compiler Author Operating System IDE? License type
AMPC Axiomatic Solutions Sdn Bhd Windows,Unix & Other Yes Proprietary
Amsterdam Compiler Kit Andrew Tanenbaum and Ceriel Jacobs Unix & Other No BSD
CCS C Compiler CCS, Inc. Windows,Unix & Other Yes Proprietary
Clang Low-Level Virtual Machine Windows,Unix & Other No BSD
DMS Software Reengineering Toolkit Semantic Designs Windows,Unix & Other No Proprietary
GCC C GNU Project Windows,Unix,IBM mainframe, AmigaOS, VAX/VMS, RTEMS No GPL
RCC (RCOR C Compiler) Rodrigo Caetano (rcor) Windows,Unix No GPL
Interactive C KISS Institute for Practical Robotics Windows, Unix, Mac, Linux, IRIX, Solaris, SunOS No Freeware
LabWindows/CVI National Instruments Windows,Unix & Other Yes Proprietary
lcc Chris Fraser and David Hanson Windows,Unix & Other Windows only Freeware (source code available for non-commercial use)
Mark Williams C Mark Williams Company Windows,Other Yes Proprietary
Microsoft C Microsoft Windows Yes Proprietary
Nwcc Nils Weller Windows,Unix,Other No BSD
Open64 SGI Google HP Intel Nvidia PathScale Tsinghua University and others Unix,Other No GPL
Pelles C Pelle Orinius Windows Yes Freeware
PGCC The Portland Group Windows,Unix,Other— Mac OS X Yes — Visual Studio on Windows Proprietary
Portable C Compiler Anders Magnusson and others Windows,Unix,Other No BSD
Power C Mix Software Other No Proprietary
QuickC Microsoft Windows Yes Proprietary
SAS/C SAS Institute Windows,Unix,Other-IBM mainframe, AmigaOS, 68K, 88K, Unix Yes Proprietary
Tiny C Compiler Fabrice Bellard Windows,Unix No LGPL
Turbo C Embarcadero Other No Proprietary - V 2.01 freely available
CCS C Compiler CCS, Inc. Windows,Unix,Other Yes Proprietary
MikroC Compiler MikroElektronika, Inc. Windows,Unix,Other Yes Proprietary
ups debugger[1] (includes C interpreter) Tom Hughes, Ian Edwards, and others Unix,Other-Solaris, SunOS Yes GPL
VBCC Dr. Volker Barthelmann Windows,Unix,Other No Freeware (source code available, modification not allowed)
XL C IBM Unix-AIX Eclipse Proprietary

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program