Your First Program in C




Introduction: Your First Program in C

This tutorial will help you create your first program in the C programming language.  

Here is what you will need:

Windows 7 Operating System (or other)
In this tutorial, you will be walked through creating your program using a Windows 7 Operating system.  Most of what you will be doing will be able to translate over the different versions of Windows, however for older versions of Windows you may have to download a different version of the software.  If you do not have a Windows 7 or other Windows based system, you may want to consider running a virtual machine on your computer running either a Windows operating system or a Linux operating system.  Tutorials on how to do this can be found on Google.

This is a free piece of software you will be using in this tutorial to create your program.  It requires either a Windows based system or a Linux based system to run.  If you do not have one of these, there are clients online that will allow you to run a virtual machine that runs either of these systems.  This tutorial will go over how to download and install this program to your computer.

Step 1: Download Dev/C++

For this section, I am running on a Windows 7 operating system.  If you are on a different operating system, the steps may be similar, but make sure that you download the correct version of the software.

1. Go to Download Site

Follow this link to take you to the website to download the software:

2. Select and Download

In this tutorial, I will be using Dev-C++ beta 9.2 ( with Mingw/GCC. Select this by clicking the SourceForge link underneath the title.  The version is outlined in red, and the download link is outlined in blue as see in the figure above.

The download should begin automatically.  Select the location to save the file and hit save.

Step 2: Install Dev/C++

1. Open the file

When the file is done downloading, locate the downloaded file and open the executable file (devcpp-

2. Instal Dev/C++

After you open the executable file, you will be ran through an installation set-up.  You can choose where to store the program files, but use the default settings for everything else.  

At the end of the installation, you can leave the box that says Run Dev-C ++ 5 beta 9 release ( selected as shown in the figure so the program will open.

Step 3: Create First Project

1. Run Dev/C++

**If you selected to run the program at the end of installation, you can skip to step 2,**

Go to Start Menu > All Programs > Bloodshed Dev-C++ > Dev-C++.  This should start the program.

2. Create a New Source File

**If you are prompted with a set up window, use all the default settings**

Once the program opens, you need to create a new source file so you can start writing your first program.  To do this select File > New > Source File.  The path is shown in the figure above.  This will open up an area where you be able to type out your code.

Step 4: Write Your Program

Here we will write the first simple program to simply have the computer say display text to the console. 

1. Copy the following code.

Copy this code into the text area:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_NAME_SZ 256

int main(int argC, char *argV[]) {
    /* Initalize variables */
    static char name[MAX_NAME_SZ+1];

    /* Ask user for name. */
    printf("What is your name? ");

    /* Get the name, with size limit. */
    fgets (name, MAX_NAME_SZ, stdin);

    /* Remove trailing newline, if there. */
    if ((strlen(name)>0) && (name[strlen (name) - 1] == '\n')){
        name[strlen (name) - 1] = '\0';

    /* Print Message. */
    printf("\nCongradulations %s!\n\nYou have made your first functional program in C.\n", name);
    printf("Have fun learning more about programming!\n\n");

    /* Pause the Console */

    /* Free memory and exit. */
    free (name);
    return 0;

2. Examine Code

To begin learning about what the different funtions are doing, read the comments seen in blue font in the code between the /* and the */.  This will describe the general idea of what is happening in the code following.

Step 5: Save and Compile Code

1. Save File

Save your file by going to File > Save As.  Select save location and name your file

Make sure you change the file type to a C source file (*.c).  This is under the save as type.

2. Compile Code

Compile your code by going to Execute > Compile.  This will check through the code to make sure that it is a valid C file.  When the compilation is complete, close the compile window.

Step 6: Run Your Code

1. Run Code

To run your code, select Execute > Run.  This will start the program and should bring up a new console as seen in the figure below.

2. Follow the Code

Follow and execute what the code is saying.  When it prompts you to enter your name, type your name and hit Enter using your keyboard.  A video demonstration of this step can be seen below.

3. Close Program

After the program has finished running, the console will print out "Press any key to continue . . ."  To end the program, simply type any key.

Step 7: More Resources

You have now completed your first program.  But don't stop here there is still much to learn about this great programming language, including arrays, loops, and pointers.  There are many great resources available on the internet and in bookstores.  Here are a few good reference books that you can check out if you want to continue learning about C

- The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
- C in a Nutshell by Peter Prinz and Tony Crawford
- C for Dummies by  Dan Gookin

A great online reference that includes documentation about all of the classes available to you in the C library is also avaliable for you for free online at

Photo credit

Be the First to Share


    • Organization Challenge

      Organization Challenge
    • Block Code Contest

      Block Code Contest
    • Cold Challenge

      Cold Challenge



    5 years ago

    First of all this is the original C program:

    #include <stdio.h>

    #include <stdlib.h>

    int main()



    return 0;



    6 years ago

    One thing i do not understand. It says "Make your first program". First program should print Hello World on screen not some fancy thing. I am not pro i just started learning C and first program shoud be this


    int main(void)
    printf("Hello world");
    return 0;

    PS: Written on android so sorry for mistakes if any.


    Reply 6 years ago

    I've never down anything with C at all but I think that you should write int main() instead of int main(void). Void means that you don't return anything and the program freaks out when you give it return 0;.


    Reply 6 years ago

    That is not true, because in "int main(void) {}" the 'void' between the parenthesis means that id doesn't take any parameters, the actual return type of it is 'int', thats why you write "*int* main(void){}".


    7 years ago on Introduction

    Thanks for the instructable. I encountered a warning for line 30 "attempt to free a non-heap object 'name' ". If I'm not wrong, it's safe to remove that line.


    9 years ago on Step 7

    says "Source file not compiled" but I compiled it.


    Reply 8 years ago on Step 7

    You need to save the project as a .C ext, then compile and run.


    Reply 9 years ago on Introduction

    It was probably a result of the file not passing the compile. Make sure that the code is copied exactly like listed and try to compile again.

    This instructable inspired me to give Dev-C++ a whirl as I'm an old guy from waaay back in the Basic, QBasic days. But I struggled and struggled with it, depreciated codes, etc., etc. then I ran across this article: and took their advice and downloaded a different (supported & updated) compiler. As soon as I tried the traditional "Hello World" in Code::Blocks it revealed one error and suggestions on how to fix it, after which it ran perfectly.

    For newbies, I would suggest they do the same as Dev-C++ hasn't been updated since 2005. If they plan to continue exploring and learning to code, doing so with something like Code::Blocks will save them hours of frustration. (I'm not affiliated with or have no personal interest in  Code::Blocks in particular, it was just highly recommended and the one I happened to try. People should do their own research and choose for themselves).

    But thank you for this instructable, which without I wouldn't have tried either!


    9 years ago on Introduction

    Nice but this should be your second program, your first should print "Hello World". This is a tradition.


    Reply 9 years ago on Introduction

    Thanks. I know that the first program is more traditionally the stock "Hello World" program, but for my class that I made this for we needed to include a video of some sort, so I decided to go with more of an interactive program that would look more interesting when ran. Thanks for viewing!