C Programming

Your First C Program

Posted on 02nd May 2013

In this chapter you will learn how to write a simple C program, how to compile and then execute it.

All examples in this tutorial are written and compiled on Windows platform using Visual Studio Express 2012 for Desktop Edition IDE. If you choose a different platform or IDE, please refer to your compiler\'s / IDE\'s documentation for help.

I. Writing your Program

Step 1: Open Visual Studio by clicking on the VS Express for Desktop icon on your start menu.

Step 2: Click File → New Project
Select Visual C++ from Templates and select Win32 Console Application.
Enter CTutorial in the name field.
Choose a folder location for your program.
Click OK.

Console Application

Step 3: Click Next in the Win32 Application Wizard Welcome screen.

Win32 Application Wizard

Step 4: Select Empty project and click Finish.

Visual Studio Empty Project

Step 5: In the Solution Explorer window of your project, right click Source Files. Select Add → New Item from the popup menu.

Visual Studio Solution Explorer

Step 6: In the Add New Item screen select C++ File. Enter the name FirstProgram.c and click Add
Note: C programs should have the filename extension .c

Step 7: Now you are all set to write to first c program. We can start with a basic program that prints a message. Key in the following program in your code window.
C is a case sensitive language. You should type this program as it is, using the correct case.

#include <stdio.h>
int main() 
	printf("Hello, I am an aspiring C Programmer");
	return (0);

II. Compiling your Program

To compile your program press CTRL+F7 or select BUILD → Compile option from the menu.
You should see the following message in the output window if your program compiled successfully.

Compile C Program

III. Running your Program

To run the program press the F5 key or select BUILD → Start Debugging from the menu.
You should see the message displayed on a console window.

Run C Program

This program is explained in detail in the next chapter.

Post a comment


Nothing yet..be the first to share wisdom.