First C language Program

Consider the following program in C programming language:

# include < stdio. h >

# include < conio. h >

void main ()


printf (“hello world!”);

getch ();



In the above program,

  • First two lines are preprocessor directive to include a header file < stdio. h> and < conio. h >. The preprocessor directives are the commands that give instructions to C preprocessor. Preprocessor is a program that modifies source program before compilation. The preprocessor directive starts with #.
  • The third line is main function. The main () function is the place where execution of C program starts. When the program is executed the control enters main () function and starts executing its statements.
  • The statements of the program are written in curly brackets. The curly bracket ‘{‘ is the opening bracket and ‘}’ is the closing bracket. The braces are also known as delimiters. These statements are collectively known as the body of a program.
  • Every statement in C program is terminated with a semicolon (;). The compiler generates an error if any statement is not terminated by semicolon.

Different parts of C program:

The format of writing C program is called its structure. The basic structure of a C program is very flexible. It increases the power of the language. It consists of the following parts:

  • Preprocessor directive
  • Header file
  • Main () function
  • Program body (C++ statements)
  • Variables
  • Expression
  • Comment

Preprocessor directive:

Preprocessor directive is an instruction given to the compiler before the execution of actual program. It is also known as compiler directive. The preprocessor directives are processed by a program known as preprocessor. It is a part of C compiler it modifies C source program before compilation. The semicolon is not used at the end of preprocessor directives.

Header files:

Header files are the collection of standard library functions (built in functions) to perform different tasks. There are many header files for different purposes. Each header file contains different types of predefined functions. Many header files can be included in one program.

The header file must be included in the program before calling any of its functions in the program as it has the definition of the built in functions. The header files are provided by the compiler and have many functions covering a range for example for mathematical functions can be used in a program by including the <cmath> header file.

Some examples of header files are as follows:

<iostream>, <conio.h>, <string>, <cmath>, etc.

For example to use the printf statement or any other input/output statement we will include < stdio. h>, then the statement will be:

# include <stdio. h>

Main function:

A function performs a single well-defined task. Every C program must have a main () function which is the first section to be executed when the program runs. When the program is executed, the control enters main () function and starts executing its statements. The word void before the function means that this function does not return a value. The curly braces {} defines the body of the main () function.

C++ statements:

A statement in C language is an instruction for the computer to perform a task. The statements are written in curly brackets. Each C statement is terminated with a semicolon.

C Environment Setup:

Turbo C IDE:

The compiler used for C language is called Turbo C IDE (Turbo C++). Turbo C++ also provides a complete integrated development environment (IDE) known as TC editor. It is used to create, edit and save programs. It also provides a powerful debugger. The debugger helps users in detecting and removing errors in programs.

The process of installing the Turbo C++ is very simple. It can be downloaded from the following link: .

The steps for installing turbo C++ are as follows.

  1. Open the link com from Google on your browser.
  2. There is a search option on the website; type Turbo C++ and click enter as shown:click enter as shown
  3. After this, there will appear the result of your search. Click on the download button
  4. Now click on the download latest version button as latest version
  5. Your download will be will be started

Creating and editing programs in turbo C++:

The process of writing C program is known as editing. This process includes writing, modifying and deleting program statements. The part of turbo C IDE that is used to write C program is called edit window. A new edit window can be opened by selecting FILE>NEW option from menu bar. The edit window appears as follows:


The edit window has a doubled lined border. The cursor blinks in the window. The position of the cursor indicates the starting point to write the program. The user can expand the window by clicking the arrow in the upper right corner. The user can also select Window > zoom to expand. The vertical and horizontal scroll bars are used to navigate through the program.

Saving a program:

  1. Select FILE>SAVE or press F2 key. The save file as dialog box will appear. The default name NONAME00.CPP appears in the dialog box.dialog box
  1. Enter the file name.
  2. Enter the path to save the file.

Compiling the program:

The process of converting a source to object code is compiling. The following procedure is used to compile a program.

Select Compile> Compile or press ALT F9 key. The program will be translated into object program if it contains no error. The compiler will generate error message if the program contains any error.

Linking a program:

The process of linking the library files with object program is known as linking. These files are used to accomplish different tasks such as input/output. A library file must be linked with the object file before execution of the program. A program that combines the object program with additional library files is known as linker. It is a part of C compiler.

The linker generates error message if the library file does not exist. A new file is created with .exe extension if the process of linking is successful. This file is known as executable file. The linker can be invoked in Turbo C++ by selecting Compiler>link from the menu bar.

Executing a program:

The process of running an executable file is known as executing. The C program can be executed after compiling and linking. The program must be loaded into the memory to execute. A program that places an executable file in the memory is known as loader. The program can be loaded in the memory by selecting Run> Run from menu bar or pressing CTRL + F9.

The screen flickers for some time when a program is executed. The output screen displays the output of the program and disappears. The user can display the output screen by selecting Window > User screen or pressing ALT + F5.

Compile and Run:

A C program can be compiled in many different ways. The best compiler to compile a C program is turbo C IDE. Consider the following steps to open turbo c IDE and write the program then to compile that program:

  1. Open Turbo C IDE from the start menu, click on file and select New:select New
  1. Now write the above example on the editor:example
  1. To compile the program click on compile or press Alt + F9press
  1. To execute the program click on Ctrl + F9 or select runclick on
  1. The output of the above program will be:output